Files
node/test/parallel/test-inspector-debug-end.js
Filip Skokan 592a0bd89c test: wait for inspector restart before exit
The self-directed debug signal restarts the inspector asynchronously.
Wait for the replacement server to listen before asking the child to
exit, instead of racing startup against a zero-delay timer.

Refs: https://github.com/nodejs/reliability/issues/1687
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66722
Refs: https://github.com/nodejs/reliability/issues/1686
Refs: https://github.com/nodejs/reliability/issues/1690
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
2026-10-16 09:48:39 +00:00

52 lines
2.0 KiB
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const { NodeInstance } = require('../common/inspector-helper.js');
async function testNoServerNoCrash() {
console.log('Test there\'s no crash stopping server that was not started');
const instance = new NodeInstance([],
`process._debugEnd();
process.exit(42);`);
assert.strictEqual((await instance.expectShutdown()).exitCode, 42);
}
async function testNoSessionNoCrash() {
console.log('Test there\'s no crash stopping server without connecting');
const instance = new NodeInstance('--inspect=0',
'process._debugEnd();process.exit(42);');
assert.strictEqual((await instance.expectShutdown()).exitCode, 42);
}
async function testSessionNoCrash() {
console.log('Test there\'s no crash stopping server after connecting');
const script = `process._debugEnd();
process.stdin.once('data', () => {
console.log("Done");
process.exit(42);
});
process._debugProcess(process.pid);`;
const instance = new NodeInstance('--inspect-brk=0', script);
const session = await instance.connectInspectorSession();
await session.send({ method: 'NodeRuntime.enable' });
await session.waitForNotification('NodeRuntime.waitingForDebugger');
instance.resetPort();
await session.send({ 'method': 'Runtime.runIfWaitingForDebugger' });
await session.waitForServerDisconnect();
// _debugProcess() starts the inspector asynchronously. Wait for the new
// server to listen before asking the child to exit.
await instance.portPromise;
instance.write('exit');
assert.strictEqual((await instance.expectShutdown()).exitCode, 42);
}
async function runTest() {
await testNoServerNoCrash();
await testNoSessionNoCrash();
await testSessionNoCrash();
}
runTest().then(common.mustCall());