Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: dynamic port in cluster worker disconnect
Remove common.PORT from test-cluster-worker-disconnect-on-error
possibility that a dynamic port used in another test will collide
with common.PORT.

Refs: #12376
  • Loading branch information
Sebastian Plesciuc
Sebastian Plesciuc committed Apr 17, 2017
commit 1c937a5fc279555532c9876e13883f3df0a87874
23 changes: 18 additions & 5 deletions test/parallel/test-cluster-worker-disconnect-on-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@
const common = require('../common');
const http = require('http');
const cluster = require('cluster');
const assert = require('assert');

cluster.schedulingPolicy = cluster.SCHED_NONE;

const server = http.createServer();
if (cluster.isMaster) {
server.listen(common.PORT);
const worker = cluster.fork();
let worker;

server.listen(0, common.mustCall((error) => {
assert.ifError(error);
assert(worker);

worker.send({port: server.address().port});
}));

worker = cluster.fork();
worker.on('exit', common.mustCall(() => {
server.close();
}));
} else {
server.listen(common.PORT);
server.on('error', common.mustCall((e) => {
cluster.worker.disconnect();
process.on('message', common.mustCall((msg) => {
assert(msg.port);

server.listen(msg.port);
server.on('error', common.mustCall((e) => {
cluster.worker.disconnect();
}));
}));
}