Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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: #13343
  • Loading branch information
Trott committed Jun 16, 2017
commit 753c6c54ee0dd3908b109c72469265193e094eeb
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