Skip to content

Commit

Permalink
test: fix flaky test-inspector-port-zero-cluster
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Trott committed Jun 16, 2017
1 parent f462ad1 commit 753c6c5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions test/inspector/test-inspector-port-zero-cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@ if (cluster.isMaster) {
for (const worker of [cluster.fork(),
cluster.fork(),
cluster.fork()]) {
worker.on('message', common.mustCall((message) => {
worker.on('message', (message) => {
ports.push(message.debugPort);
worker.kill();
}));
});
worker.on('exit', (code, signal) => {
// If the worker exited via `worker.kill()` above, exitedAfterDisconnect
// will be true. If the worker exited because the debug port was already
// in use, exitedAfterDisconnect will be false. That can be expected in
// some cases, so grab the port from spawnargs.
if (!worker.exitedAfterDisconnect) {
const arg = worker.process.spawnargs.filter(
(val) => /^--inspect=\d+$/.test(val)
);
const port = arg[0].replace('--inspect=', '');
ports.push(+port);
}
});
worker.send('debugPort');
}
process.on('exit', () => {
Expand Down

0 comments on commit 753c6c5

Please sign in to comment.