Skip to content

Commit 6b1819c

Browse files
vieiraarturglpinca
authored andcommitted
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: #12901 Ref: #12376 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent 8476880 commit 6b1819c

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

test/parallel/test-cluster-dgram-reuse.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@ if (cluster.isMaster) {
1616
return;
1717
}
1818

19-
const sockets = [];
20-
function next() {
21-
sockets.push(this);
22-
if (sockets.length !== 2)
23-
return;
24-
25-
// Work around health check issue
26-
process.nextTick(() => {
27-
for (let i = 0; i < sockets.length; i++)
28-
sockets[i].close(close);
29-
});
30-
}
31-
3219
let waiting = 2;
3320
function close() {
3421
if (--waiting === 0)
3522
cluster.worker.disconnect();
3623
}
3724

38-
for (let i = 0; i < 2; i++)
39-
dgram.createSocket({ type: 'udp4', reuseAddr: true }).bind(common.PORT, next);
25+
const options = { type: 'udp4', reuseAddr: true };
26+
const socket1 = dgram.createSocket(options);
27+
const socket2 = dgram.createSocket(options);
28+
29+
socket1.bind(0, () => {
30+
socket2.bind(socket1.address().port, () => {
31+
// Work around health check issue
32+
process.nextTick(() => {
33+
socket1.close(close);
34+
socket2.close(close);
35+
});
36+
});
37+
});

0 commit comments

Comments
 (0)