Commit d5958888cc3 for nodejs
commit d5958888cc3b4311c9daf876edb01ba65cbe47d5
Author: Filip Skokan <panva.ip@gmail.com>
Date: Sat Sep 26 14:20:22 2026 +0200
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: https://github.com/nodejs/node/issues/63212
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66320
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
diff --git a/test/common/debugger.js b/test/common/debugger.js
index dbaa62e71d3..73a34a76776 100644
--- a/test/common/debugger.js
+++ b/test/common/debugger.js
@@ -27,6 +27,8 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
...args,
], spawnOpts);
+ const closed = new Promise((resolve) => child.once('close', resolve));
+
const outputBuffer = [];
function bufferOutput(chunk) {
if (this === child.stderr) {
@@ -180,10 +182,8 @@ function startCLI(args, flags = [], spawnOpts = {}, opts = { randomPort: true })
},
quit() {
- return new Promise((resolve) => {
- child.stdin.end();
- child.on('close', resolve);
- });
+ child.stdin.end();
+ return closed;
},
};
}
diff --git a/test/fixtures/debugger/alive.js b/test/fixtures/debugger/alive.js
index c8ad157b452..0b06798508a 100644
--- a/test/fixtures/debugger/alive.js
+++ b/test/fixtures/debugger/alive.js
@@ -3,3 +3,5 @@ function heartbeat() {
++x;
}
setInterval(heartbeat, 50);
+
+if (process.send) process.send('ready');
diff --git a/test/sequential/sequential.status b/test/sequential/sequential.status
index a765de75950..b518481383b 100644
--- a/test/sequential/sequential.status
+++ b/test/sequential/sequential.status
@@ -7,8 +7,6 @@ prefix sequential
[true] # This section applies to all platforms
[$system==win32]
-# https://github.com/nodejs/node/issues/63212#issuecomment-5423558796
-test-debugger-pid: PASS, FLAKY
[$system==linux]
# https://github.com/nodejs/node/issues/54817
diff --git a/test/sequential/test-debugger-pid.js b/test/sequential/test-debugger-pid.js
index 97218b796ca..f05f968e460 100644
--- a/test/sequential/test-debugger-pid.js
+++ b/test/sequential/test-debugger-pid.js
@@ -8,11 +8,15 @@ const startCLI = require('../common/debugger');
const assert = require('assert');
const { spawn } = require('child_process');
+const { once } = require('events');
const script = fixtures.path('debugger', 'alive.js');
(async () => {
- const target = spawn(process.execPath, [script]);
+ const target = spawn(process.execPath, [script], {
+ stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
+ });
+ await once(target, 'message');
const cli = startCLI(['-p', `${target.pid}`], [], {}, { randomPort: false });
try {
@@ -25,7 +29,8 @@ const script = fixtures.path('debugger', 'alive.js');
/> 3 {3}\+\+x;/,
'marks the 3rd line');
} finally {
- await cli.quit();
+ const targetClosed = once(target, 'close');
target.kill();
+ await Promise.all([cli.quit(), targetClosed]);
}
})().then(common.mustCall());
diff --git a/test/sequential/test-debugger-quit-after-exit.js b/test/sequential/test-debugger-quit-after-exit.js
new file mode 100644
index 00000000000..7e02175435b
--- /dev/null
+++ b/test/sequential/test-debugger-quit-after-exit.js
@@ -0,0 +1,12 @@
+'use strict';
+const common = require('../common');
+common.skipIfInspectorDisabled();
+
+const assert = require('assert');
+const startCLI = require('../common/debugger');
+
+(async () => {
+ const cli = startCLI(['--help'], [], {}, { randomPort: false });
+ await assert.rejects(cli.waitForPrompt(), /Child exited while waiting/);
+ await cli.quit();
+})().then(common.mustCall());