Skip to content

Commit 6a86ada

Browse files
committed
test: use dynamic port in test-cluster-bind-twice
Remove common.PORT from test-cluster-bind-twice to eliminate possibility that a dynamic port used in another test will collide with common.PORT. Refs: #12376
1 parent c05e5bf commit 6a86ada

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

test/parallel/test-cluster-bind-twice.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ if (!id) {
6767

6868

6969
a.on('message', common.mustCall((m) => {
70-
if (typeof m === 'object') return;
71-
assert.strictEqual(m, 'READY');
72-
b.send('START');
70+
assert.strictEqual(m.msg, 'READY');
71+
b.send({msg: 'START', port: m.port});
7372
}));
7473

7574
b.on('message', common.mustCall((m) => {
@@ -81,10 +80,10 @@ if (!id) {
8180
} else if (id === 'one') {
8281
if (cluster.isMaster) return startWorker();
8382

84-
http.createServer(common.mustNotCall())
85-
.listen(common.PORT, common.mustCall(() => {
86-
process.send('READY');
87-
}));
83+
const server = http.createServer(common.mustNotCall());
84+
server.listen(0, common.mustCall(() => {
85+
process.send({msg: 'READY', port: server.address().port});
86+
}));
8887

8988
process.on('message', common.mustCall((m) => {
9089
if (m === 'QUIT') process.exit();
@@ -95,8 +94,8 @@ if (!id) {
9594
const server = http.createServer(common.mustNotCall());
9695
process.on('message', common.mustCall((m) => {
9796
if (m === 'QUIT') process.exit();
98-
assert.strictEqual(m, 'START');
99-
server.listen(common.PORT, common.mustNotCall());
97+
assert.strictEqual(m.msg, 'START');
98+
server.listen(m.port, common.mustNotCall());
10099
server.on('error', common.mustCall((e) => {
101100
assert.strictEqual(e.code, 'EADDRINUSE');
102101
process.send(e.code);

0 commit comments

Comments
 (0)