Skip to content

Commit 9c5c469

Browse files
Sebastian Plesciucjasnell
Sebastian Plesciuc
authored andcommitted
test: dynamic port in cluster worker send
Remove common.PORT from test-cluster-send-deadlock and test-cluster-send-handle-twice to reduce possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: #12472 Ref: #12376 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent d78fd26 commit 9c5c469

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

test/parallel/test-cluster-send-deadlock.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// Testing mutual send of handles: from master to worker, and from worker to
2424
// master.
2525

26-
const common = require('../common');
26+
require('../common');
2727
const assert = require('assert');
2828
const cluster = require('cluster');
2929
const net = require('net');
@@ -40,14 +40,15 @@ if (cluster.isMaster) {
4040
worker.send('handle', socket);
4141
});
4242

43-
server.listen(common.PORT, function() {
44-
worker.send('listen');
43+
server.listen(0, function() {
44+
worker.send({message: 'listen', port: server.address().port});
4545
});
4646
} else {
4747
process.on('message', function(msg, handle) {
48-
if (msg === 'listen') {
49-
const client1 = net.connect({ host: 'localhost', port: common.PORT });
50-
const client2 = net.connect({ host: 'localhost', port: common.PORT });
48+
if (msg.message && msg.message === 'listen') {
49+
assert(msg.port);
50+
const client1 = net.connect({ host: 'localhost', port: msg.port });
51+
const client2 = net.connect({ host: 'localhost', port: msg.port });
5152
let waiting = 2;
5253
client1.on('close', onclose);
5354
client2.on('close', onclose);

test/parallel/test-cluster-send-handle-twice.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ if (cluster.isMaster) {
4545
process.send('send-handle-2', socket);
4646
});
4747

48-
server.listen(common.PORT, function() {
49-
const client = net.connect({ host: 'localhost', port: common.PORT });
48+
server.listen(0, function() {
49+
const client = net.connect({
50+
host: 'localhost',
51+
port: server.address().port
52+
});
5053
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
5154
setTimeout(function() { client.end(); }, 50);
5255
}).on('error', function(e) {

0 commit comments

Comments
 (0)