Skip to content
Permalink
Browse files

test: dynamic port in cluster disconnect

Removed common.PORT from test-cluster-disconnect to eliminate the
possibility that a port used in another test will collide
with common.PORT.

PR-URL: #12545
Refs: #12376
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information...
Sebastian Plesciuc authored and gibfahn committed May 4, 2017
1 parent 54d3318 commit bee250c2326dc9424ff4b940d34a5bd7017022c1
Showing with 9 additions and 5 deletions.
  1. +9 −5 test/parallel/test-cluster-disconnect.js
@@ -28,14 +28,14 @@ const net = require('net');
if (cluster.isWorker) {
net.createServer((socket) => {
socket.end('echo');
}).listen(common.PORT, '127.0.0.1');
}).listen(0, '127.0.0.1');

net.createServer((socket) => {
socket.end('echo');
}).listen(common.PORT + 1, '127.0.0.1');

}).listen(0, '127.0.0.1');
} else if (cluster.isMaster) {
const servers = 2;
const serverPorts = new Set();

// test a single TCP server
const testConnection = (port, cb) => {
@@ -47,16 +47,18 @@ if (cluster.isWorker) {
// check result
socket.on('end', common.mustCall(() => {
cb(result === 'echo');
serverPorts.delete(port);
}));
});
};

// test both servers created in the cluster
const testCluster = (cb) => {
let done = 0;
const portsArray = Array.from(serverPorts);

for (let i = 0; i < servers; i++) {
testConnection(common.PORT + i, (success) => {
testConnection(portsArray[i], (success) => {
assert.ok(success);
done += 1;
if (done === servers) {
@@ -72,7 +74,9 @@ if (cluster.isWorker) {
let online = 0;

for (let i = 0, l = workers; i < l; i++) {
cluster.fork().on('listening', common.mustCall(() => {
cluster.fork().on('listening', common.mustCall((address) => {
serverPorts.add(address.port);

online += 1;
if (online === workers * servers) {
cb();

0 comments on commit bee250c

Please sign in to comment.
You can’t perform that action at this time.