Skip to content

Commit 7455346

Browse files
committed
test: refactor test-cluster-send-deadlock
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>
1 parent 0ac4ef9 commit 7455346

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

test/parallel/test-cluster-send-deadlock.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,25 @@ if (cluster.isMaster) {
4747
process.on('message', function(msg, handle) {
4848
if (msg.message && msg.message === 'listen') {
4949
assert(msg.port);
50-
const client1 = net.connect({ host: 'localhost', port: msg.port });
51-
const client2 = net.connect({ host: 'localhost', port: msg.port });
50+
const client1 = net.connect({
51+
host: 'localhost',
52+
port: msg.port
53+
}, function() {
54+
const client2 = net.connect({
55+
host: 'localhost',
56+
port: msg.port
57+
}, function() {
58+
client1.on('close', onclose);
59+
client2.on('close', onclose);
60+
client1.end();
61+
client2.end();
62+
});
63+
});
5264
let waiting = 2;
53-
client1.on('close', onclose);
54-
client2.on('close', onclose);
5565
function onclose() {
5666
if (--waiting === 0)
5767
cluster.worker.disconnect();
5868
}
59-
setTimeout(function() {
60-
client1.end();
61-
client2.end();
62-
}, 50);
6369
} else {
6470
process.send('reply', handle);
6571
}

0 commit comments

Comments
 (0)