Skip to content

Commit

Permalink
test: dynamic port in cluster worker send
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
  • Loading branch information
Sebastian Plesciuc authored and MylesBorins committed May 18, 2017
1 parent a755ef0 commit ce3b544
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 7 additions & 6 deletions test/parallel/test-cluster-send-deadlock.js
Expand Up @@ -2,7 +2,7 @@
// Testing mutual send of handles: from master to worker, and from worker to
// master.

const common = require('../common');
require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
Expand All @@ -19,14 +19,15 @@ if (cluster.isMaster) {
worker.send('handle', socket);
});

server.listen(common.PORT, function() {
worker.send('listen');
server.listen(0, function() {
worker.send({message: 'listen', port: server.address().port});
});
} else {
process.on('message', function(msg, handle) {
if (msg === 'listen') {
const client1 = net.connect({ host: 'localhost', port: common.PORT });
const client2 = net.connect({ host: 'localhost', port: common.PORT });
if (msg.message && msg.message === 'listen') {
assert(msg.port);
const client1 = net.connect({ host: 'localhost', port: msg.port });
const client2 = net.connect({ host: 'localhost', port: msg.port });
let waiting = 2;
client1.on('close', onclose);
client2.on('close', onclose);
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-cluster-send-handle-twice.js
Expand Up @@ -24,8 +24,11 @@ if (cluster.isMaster) {
process.send('send-handle-2', socket);
});

server.listen(common.PORT, function() {
const client = net.connect({ host: 'localhost', port: common.PORT });
server.listen(0, function() {
const client = net.connect({
host: 'localhost',
port: server.address().port
});
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
setTimeout(function() { client.end(); }, 50);
}).on('error', function(e) {
Expand Down

0 comments on commit ce3b544

Please sign in to comment.