Skip to content

Commit f48d06c

Browse files
Sebastian Plesciucevanlucas
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 a75fbe0 commit f48d06c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Testing mutual send of handles: from master to worker, and from worker to
33
// master.
44

5-
const common = require('../common');
5+
require('../common');
66
const assert = require('assert');
77
const cluster = require('cluster');
88
const net = require('net');
@@ -19,14 +19,15 @@ if (cluster.isMaster) {
1919
worker.send('handle', socket);
2020
});
2121

22-
server.listen(common.PORT, function() {
23-
worker.send('listen');
22+
server.listen(0, function() {
23+
worker.send({message: 'listen', port: server.address().port});
2424
});
2525
} else {
2626
process.on('message', function(msg, handle) {
27-
if (msg === 'listen') {
28-
const client1 = net.connect({ host: 'localhost', port: common.PORT });
29-
const client2 = net.connect({ host: 'localhost', port: common.PORT });
27+
if (msg.message && msg.message === 'listen') {
28+
assert(msg.port);
29+
const client1 = net.connect({ host: 'localhost', port: msg.port });
30+
const client2 = net.connect({ host: 'localhost', port: msg.port });
3031
let waiting = 2;
3132
client1.on('close', onclose);
3233
client2.on('close', onclose);

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ if (cluster.isMaster) {
2424
process.send('send-handle-2', socket);
2525
});
2626

27-
server.listen(common.PORT, function() {
28-
const client = net.connect({ host: 'localhost', port: common.PORT });
27+
server.listen(0, function() {
28+
const client = net.connect({
29+
host: 'localhost',
30+
port: server.address().port
31+
});
2932
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
3033
setTimeout(function() { client.end(); }, 50);
3134
}).on('error', function(e) {

0 commit comments

Comments
 (0)