Skip to content

Commit

Permalink
test: fix flaky test-cluster-send-handle-twice
Browse files Browse the repository at this point in the history
Use `common.mustCall()` to make sure connection callback runs exactly
once.

Use `connect` event instead of `setTimeout` to avoid test failing if
timer runs before client is connected.

Remove `cluster.worker.disconnect()` after `assert.fail()`. It is
unreachable code that is unnecessary.

PR-URL: #19700
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and BethGriggs committed Dec 4, 2018
1 parent 33b7c50 commit a7b3274
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions test/parallel/test-cluster-send-handle-twice.js
Expand Up @@ -40,21 +40,20 @@ if (cluster.isMaster) {
}));
}
} else {
const server = net.createServer(function(socket) {
const server = net.createServer(common.mustCall((socket) => {
process.send('send-handle-1', socket);
process.send('send-handle-2', socket);
});
}));

server.listen(0, function() {
const client = net.connect({
host: 'localhost',
port: server.address().port
});
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
setTimeout(function() { client.end(); }, 50);
client.on('connect', () => { client.end(); });
}).on('error', function(e) {
console.error(e);
assert.fail('server.listen failed');
cluster.worker.disconnect();
});
}

0 comments on commit a7b3274

Please sign in to comment.