Skip to content

Commit 2ff7cfc

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. Use setContextLineNumber(2) to probe the debugger CLI state. The command requires a pause state and leaves the default context line setting unchanged. Retry while it reports that execution is not paused. Wait for the probe response and the next prompt together, so later test commands cannot consume probe output. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5
1 parent bfb2fa7 commit 2ff7cfc

1 file changed

Lines changed: 44 additions & 9 deletions

File tree

test/common/debugger.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ 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;
10+
const PAUSE_STATE_MESSAGE =
11+
/requires execution to be paused|contextLine has been changed/i;
912

1013
let TIMEOUT = common.platformTimeout(10000);
1114
// Some macOS and Windows machines require more time to receive the outputs from the client.
@@ -56,7 +59,7 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
5659
return output;
5760
},
5861

59-
waitFor(pattern) {
62+
waitFor(pattern, offset = 0, timeout = TIMEOUT) {
6063
function checkPattern(str) {
6164
if (Array.isArray(pattern)) {
6265
return pattern.every((p) => p.test(str));
@@ -66,9 +69,10 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
6669

6770
return new Promise((resolve, reject) => {
6871
function checkOutput() {
69-
if (checkPattern(getOutput())) {
72+
const output = getOutput().slice(offset);
73+
if (checkPattern(output)) {
7074
tearDown();
71-
resolve();
75+
resolve(output);
7276
}
7377
}
7478

@@ -89,12 +93,12 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
8993
}
9094

9195
// 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}`);
96+
const timeoutErr = new Error(`Timeout (${timeout}) while waiting for ${pattern}`);
9397
const timer = setTimeout(() => {
9498
tearDown();
9599
timeoutErr.output = this.output;
96100
reject(timeoutErr);
97-
}, TIMEOUT);
101+
}, timeout);
98102

99103
function tearDown() {
100104
clearTimeout(timer);
@@ -108,16 +112,47 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
108112
});
109113
},
110114

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

115150
async waitForInitialBreak() {
116-
await this.waitFor(/break (?:on start )?in/i);
151+
await this.waitForPaused();
117152

118153
if (isPreBreak(this.output)) {
119154
await this.command('next', false);
120-
return this.waitFor(/break in/);
155+
await this.waitForPaused();
121156
}
122157
},
123158

0 commit comments

Comments
 (0)