From d5af03c1bbf382da45bd8e7ad72539d5189f813a Mon Sep 17 00:00:00 2001 From: Rafael Fragoso Date: Sat, 15 Apr 2017 10:23:26 -0300 Subject: [PATCH 1/4] test: use dynamic port in test-cluster-dgram-reuse.js Remove common.PORT from test-cluster-dgram-reuse to eliminate possibility that a dynamic port used in another test will collide with common.PORT. Refs: https://github.com/nodejs/node/issues/12376 --- test/parallel/test-cluster-dgram-reuse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js index aed565a3806e97..f81dbbc5a099f2 100644 --- a/test/parallel/test-cluster-dgram-reuse.js +++ b/test/parallel/test-cluster-dgram-reuse.js @@ -37,4 +37,4 @@ function close() { } for (let i = 0; i < 2; i++) - dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next); + dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(0, next); From 43bce0a8dd328e3135ecbc141be73cb0292a612f Mon Sep 17 00:00:00 2001 From: Rafael Fragoso Date: Sat, 15 Apr 2017 11:39:52 -0300 Subject: [PATCH 2/4] test: using the dynamic port for both sockets in test-cluster-dgram-reuse Using the bind() callback to get the dynamically assigned port from the first socket and assigning it to the next cluster. --- test/parallel/test-cluster-dgram-reuse.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js index f81dbbc5a099f2..4176d85ffa5ee5 100644 --- a/test/parallel/test-cluster-dgram-reuse.js +++ b/test/parallel/test-cluster-dgram-reuse.js @@ -36,5 +36,12 @@ function close() { cluster.worker.disconnect(); } -for (let i = 0; i < 2; i++) - dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(0, next); +// Creates the first socket +const socket = dgram.createSocket({ type: 'udp4', reuseAddr: true }); +// Let the OS assign a random port to the first socket +socket.bind(0, function() { + // Creates the second socket using the same port from the previous one + dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(socket.address().port, next); + // Call next for the first socket + next.call(this); +}); From 7ddb0932d1827592cf64868166b2d5affd55d0c4 Mon Sep 17 00:00:00 2001 From: Rafael Fragoso Date: Sat, 15 Apr 2017 13:58:07 -0300 Subject: [PATCH 3/4] test: fixing the wordwrap in test-cluster-dgram-reuse Fixes the wordwrap error of my last commit based on the guidelines --- test/parallel/test-cluster-dgram-reuse.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js index 4176d85ffa5ee5..7f5abcf17c3c1e 100644 --- a/test/parallel/test-cluster-dgram-reuse.js +++ b/test/parallel/test-cluster-dgram-reuse.js @@ -41,7 +41,8 @@ const socket = dgram.createSocket({ type: 'udp4', reuseAddr: true }); // Let the OS assign a random port to the first socket socket.bind(0, function() { // Creates the second socket using the same port from the previous one - dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(socket.address().port, next); + dgram.createSocket({ type: 'udp4', reuseAddr: true }) + .bind(socket.address().port, next); // Call next for the first socket next.call(this); }); From bab6ccca86a25a3384caa9de2cace91f8b29c659 Mon Sep 17 00:00:00 2001 From: Rafael Fragoso Date: Sat, 15 Apr 2017 17:03:03 -0300 Subject: [PATCH 4/4] test: adding common.mustCall() to callback Adding the common.mustCall() to the callback as the test documentation explains it. --- test/parallel/test-cluster-dgram-reuse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-cluster-dgram-reuse.js b/test/parallel/test-cluster-dgram-reuse.js index 7f5abcf17c3c1e..0196ffb5a9bccf 100644 --- a/test/parallel/test-cluster-dgram-reuse.js +++ b/test/parallel/test-cluster-dgram-reuse.js @@ -39,10 +39,10 @@ function close() { // Creates the first socket const socket = dgram.createSocket({ type: 'udp4', reuseAddr: true }); // Let the OS assign a random port to the first socket -socket.bind(0, function() { +socket.bind(0, common.mustCall(function() { // Creates the second socket using the same port from the previous one dgram.createSocket({ type: 'udp4', reuseAddr: true }) .bind(socket.address().port, next); // Call next for the first socket next.call(this); -}); +}));