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()`.
  • Loading branch information
lpinca committed Mar 21, 2018
1 parent d25dea7 commit 5b957e1
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 5b957e1

Please sign in to comment.