Skip to content

Commit 56ea5cb

Browse files
committed
test: wait for debugger pause state on startup
The debugger helper waited for the initial break by matching the human-readable break banner. On slow systems the CLI can reach the prompt before that banner is observed, causing flaky timeouts. Probe the debugger CLI state with list() and retry while it reports that execution is not paused. Use the remaining timeout budget for each probe wait so the startup wait still respects the helper timeout. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5
1 parent 6cde237 commit 56ea5cb

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

test/common/debugger.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const BREAK_MESSAGE = new RegExp('(?:' + [
66
'assert', 'break', 'break on start', 'debugCommand',
77
'exception', 'other', 'promiseRejection', 'step',
88
].join('|') + ') in', 'i');
9+
const NOT_PAUSED_MESSAGE = /requires execution to be paused/i;
910

1011
let TIMEOUT = common.platformTimeout(10000);
1112
// Some macOS and Windows machines require more time to receive the outputs from the client.
@@ -56,7 +57,7 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
5657
return output;
5758
},
5859

59-
waitFor(pattern) {
60+
waitFor(pattern, offset = 0, timeout = TIMEOUT) {
6061
function checkPattern(str) {
6162
if (Array.isArray(pattern)) {
6263
return pattern.every((p) => p.test(str));
@@ -66,9 +67,10 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
6667

6768
return new Promise((resolve, reject) => {
6869
function checkOutput() {
69-
if (checkPattern(getOutput())) {
70+
const output = getOutput().slice(offset);
71+
if (checkPattern(output)) {
7072
tearDown();
71-
resolve();
73+
resolve(output);
7274
}
7375
}
7476

@@ -89,12 +91,12 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
8991
}
9092

9193
// Capture stack trace here to show where waitFor was called from when it times out.
92-
const timeoutErr = new Error(`Timeout (${TIMEOUT}) while waiting for ${pattern}`);
94+
const timeoutErr = new Error(`Timeout (${timeout}) while waiting for ${pattern}`);
9395
const timer = setTimeout(() => {
9496
tearDown();
9597
timeoutErr.output = this.output;
9698
reject(timeoutErr);
97-
}, TIMEOUT);
99+
}, timeout);
98100

99101
function tearDown() {
100102
clearTimeout(timer);
@@ -108,16 +110,44 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
108110
});
109111
},
110112

111-
waitForPrompt() {
112-
return this.waitFor(/>\s+$/);
113+
async waitForPaused() {
114+
const deadline = Date.now() + TIMEOUT;
115+
116+
function getRemainingTime() {
117+
return deadline - Date.now();
118+
}
119+
120+
await this.waitForPrompt(getRemainingTime());
121+
122+
while (getRemainingTime() > 0) {
123+
const offset = this.output.length;
124+
this.writeLine('list()', false);
125+
const output = await this.waitFor(/>\s+$/, offset, getRemainingTime());
126+
127+
if (!NOT_PAUSED_MESSAGE.test(output)) {
128+
return;
129+
}
130+
131+
await new Promise((resolve) =>
132+
setTimeout(resolve, Math.min(100, getRemainingTime())));
133+
}
134+
135+
const timeoutErr =
136+
new Error(`Timeout (${TIMEOUT}) while waiting for a debugger pause state`);
137+
timeoutErr.output = this.output;
138+
throw timeoutErr;
139+
},
140+
141+
waitForPrompt(timeout = TIMEOUT) {
142+
return this.waitFor(/>\s+$/, 0, timeout);
113143
},
114144

115145
async waitForInitialBreak() {
116-
await this.waitFor(/break (?:on start )?in/i);
146+
await this.waitForPaused();
117147

118148
if (isPreBreak(this.output)) {
119149
await this.command('next', false);
120-
return this.waitFor(/break in/);
150+
await this.waitForPaused();
121151
}
122152
},
123153

0 commit comments

Comments
 (0)