From 6b1819cff59c674d03f0afca80f33369b36b3926 Mon Sep 17 00:00:00 2001 From: Artur Vieira Date: Mon, 8 May 2017 09:38:53 +0000 Subject: [PATCH] test: use dynamic port in test-cluster-dgram-reuse Remove common.PORT from test-cluster-dgram-reuse to eliminate possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: https://github.com/nodejs/node/pull/12901 Ref: https://github.com/nodejs/node/issues/12376 Reviewed-By: Luigi Pinca Reviewed-By: Matteo Collina Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Daijiro Wachi --- test/parallel/test-cluster-dgram-reuse.js | 28 +++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js index cdb7cc9a4a5ae1..1472dcc5238a63 100644 --- a/test/parallel/test-cluster-dgram-reuse.js +++ b/test/parallel/test-cluster-dgram-reuse.js @@ -16,24 +16,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); + }); + }); +});