Skip to content

Commit

Permalink
test: use dynamic port in test-cluster-dgram-reuse
Browse files Browse the repository at this point in the history
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: #12901
Ref: #12376
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
  • Loading branch information
arturgvieira authored and MylesBorins committed Jul 17, 2017
1 parent 5fe6840 commit 3e5e38e
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions test/parallel/test-cluster-dgram-reuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 3e5e38e

Please sign in to comment.