Skip to content

Commit 753c6c5

Browse files
committed
test: fix flaky test-inspector-port-zero-cluster
With a properly functioning test, it is possible for a cluster worker to fail to launch due to a port collision. For better or for worse, this is working as expected and so the test now accommodates that reality. Fixes: nodejs#13343
1 parent f462ad1 commit 753c6c5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

test/inspector/test-inspector-port-zero-cluster.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@ if (cluster.isMaster) {
1212
for (const worker of [cluster.fork(),
1313
cluster.fork(),
1414
cluster.fork()]) {
15-
worker.on('message', common.mustCall((message) => {
15+
worker.on('message', (message) => {
1616
ports.push(message.debugPort);
1717
worker.kill();
18-
}));
18+
});
19+
worker.on('exit', (code, signal) => {
20+
// If the worker exited via `worker.kill()` above, exitedAfterDisconnect
21+
// will be true. If the worker exited because the debug port was already
22+
// in use, exitedAfterDisconnect will be false. That can be expected in
23+
// some cases, so grab the port from spawnargs.
24+
if (!worker.exitedAfterDisconnect) {
25+
const arg = worker.process.spawnargs.filter(
26+
(val) => /^--inspect=\d+$/.test(val)
27+
);
28+
const port = arg[0].replace('--inspect=', '');
29+
ports.push(+port);
30+
}
31+
});
1932
worker.send('debugPort');
2033
}
2134
process.on('exit', () => {

0 commit comments

Comments
 (0)