Skip to content

Commit

Permalink
test: refactor test-cluster-send-deadlock
Browse files Browse the repository at this point in the history
Wait for the sockets to be connected before closing them and remove
unneeded `setTimeout()`.

PR-URL: #19241
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
lpinca committed Mar 21, 2018
1 parent 0ac4ef9 commit 7455346
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/parallel/test-cluster-send-deadlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,25 @@ if (cluster.isMaster) {
process.on('message', function(msg, handle) {
if (msg.message && msg.message === 'listen') {
assert(msg.port);
const client1 = net.connect({ host: 'localhost', port: msg.port });
const client2 = net.connect({ host: 'localhost', port: msg.port });
const client1 = net.connect({
host: 'localhost',
port: msg.port
}, function() {
const client2 = net.connect({
host: 'localhost',
port: msg.port
}, function() {
client1.on('close', onclose);
client2.on('close', onclose);
client1.end();
client2.end();
});
});
let waiting = 2;
client1.on('close', onclose);
client2.on('close', onclose);
function onclose() {
if (--waiting === 0)
cluster.worker.disconnect();
}
setTimeout(function() {
client1.end();
client2.end();
}, 50);
} else {
process.send('reply', handle);
}
Expand Down

0 comments on commit 7455346

Please sign in to comment.