Browse Source

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.

PR-URL: https://github.com/nodejs/node/pull/12457
Ref: https://github.com/nodejs/node/issues/12376
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
v6
Sebastian Plesciuc 8 years ago
committed by James M Snell
parent
commit
a2843f2cf9
  1. 19
      test/parallel/test-cluster-worker-disconnect-on-error.js

19
test/parallel/test-cluster-worker-disconnect-on-error.js

@ -2,19 +2,32 @@
const common = require('../common'); const common = require('../common');
const http = require('http'); const http = require('http');
const cluster = require('cluster'); const cluster = require('cluster');
const assert = require('assert');
cluster.schedulingPolicy = cluster.SCHED_NONE; cluster.schedulingPolicy = cluster.SCHED_NONE;
const server = http.createServer(); const server = http.createServer();
if (cluster.isMaster) { if (cluster.isMaster) {
server.listen(common.PORT); let worker;
const worker = cluster.fork();
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(() => { worker.on('exit', common.mustCall(() => {
server.close(); server.close();
})); }));
} else { } else {
server.listen(common.PORT); process.on('message', common.mustCall((msg) => {
assert(msg.port);
server.listen(msg.port);
server.on('error', common.mustCall((e) => { server.on('error', common.mustCall((e) => {
cluster.worker.disconnect(); cluster.worker.disconnect();
})); }));
}));
} }

Loading…
Cancel
Save