diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js index aed565a3806e97..dd51d111eb1fe9 100644 --- a/test/parallel/test-cluster-dgram-reuse.js +++ b/test/parallel/test-cluster-dgram-reuse.js @@ -17,24 +17,22 @@ if (cluster.isMaster) { return; } -const sockets = []; -function next() { - sockets.push(this); - if (sockets.length !== 2) - return; - - // Work around health check issue - process.nextTick(() => { - for (let i = 0; i < sockets.length; i++) - sockets[i].close(close); - }); -} - let waiting = 2; function close() { if (--waiting === 0) cluster.worker.disconnect(); } -for (let i = 0; i < 2; i++) - dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next); +const options = { type: 'udp4', reuseAddr: true }; +const socket1 = dgram.createSocket(options); +const socket2 = dgram.createSocket(options); + +socket1.bind(0, () => { + socket2.bind(socket1.address().port, () => { + // Work around health check issue + process.nextTick(() => { + socket1.close(close); + socket2.close(close); + }); + }); +});