test: refactor test-cluster-send-deadlock

Wait for the sockets to be connected before closing them and remove
unneeded `setTimeout()`.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Luigi Pinca 2018-03-09 11:05:38 +01:00
parent 0ac4ef9a4c
commit 74553465e6

View File

@ -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);
}