Skip to content

Commit fbdca3a

Browse files
panvaaduh95
authored andcommitted
test: deflake debugger PID attachment and cleanup
Wait for the target to finish starting before attaching the debugger. Capture the CLI close event when it is spawned so quit() also completes after an early exit, and terminate the target before awaiting cleanup. Add a regression test for quitting an already exited CLI and remove the Windows flaky entry. Refs: #63212 Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: #66320 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5345613 commit fbdca3a

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

‎test/common/debugger.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
2727
...args,
2828
], spawnOpts);
2929

30+
const closed = new Promise((resolve) => child.once('close', resolve));
31+
3032
const outputBuffer = [];
3133
function bufferOutput(chunk) {
3234
if (this === child.stderr) {
@@ -180,10 +182,8 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
180182
},
181183

182184
quit() {
183-
return new Promise((resolve) => {
184-
child.stdin.end();
185-
child.on('close', resolve);
186-
});
185+
child.stdin.end();
186+
return closed;
187187
},
188188
};
189189
}

‎test/fixtures/debugger/alive.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ function heartbeat() {
33
++x;
44
}
55
setInterval(heartbeat, 50);
6+
7+
if (process.send) process.send('ready');

‎test/sequential/sequential.status‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ test-cpu-prof-dir-worker: PASS, FLAKY
1111
test-http2-large-file: PASS, FLAKY
1212

1313
[$system==win32]
14-
# https://github.com/nodejs/node/issues/63212#issuecomment-5423558796
15-
test-debugger-pid: PASS, FLAKY
1614

1715
[$system==linux]
1816
# https://github.com/nodejs/node/issues/54817

‎test/sequential/test-debugger-pid.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ const startCLI = require('../common/debugger');
88

99
const assert = require('assert');
1010
const { spawn } = require('child_process');
11+
const { once } = require('events');
1112

1213
const script = fixtures.path('debugger', 'alive.js');
1314

1415
(async () => {
15-
const target = spawn(process.execPath, [script]);
16+
const target = spawn(process.execPath, [script], {
17+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
18+
});
19+
await once(target, 'message');
1620
const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false });
1721

1822
try {
@@ -25,7 +29,8 @@ const script = fixtures.path('debugger', 'alive.js');
2529
/> 3 {3}\+\+x;/,
2630
'marks the 3rd line');
2731
} finally {
28-
await cli.quit();
32+
const targetClosed = once(target, 'close');
2933
target.kill();
34+
await Promise.all([cli.quit(), targetClosed]);
3035
}
3136
})().then(common.mustCall());
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
4+
5+
const assert = require('assert');
6+
const startCLI = require('../common/debugger');
7+
8+
(async () => {
9+
const cli = startCLI(['--help'], [], {}, { randomPort: false });
10+
await assert.rejects(cli.waitForPrompt(), /Child exited while waiting/);
11+
await cli.quit();
12+
})().then(common.mustCall());

0 commit comments

Comments
 (0)