From a2133207451936074a9bc8caaac69ec15c56f7ca Mon Sep 17 00:00:00 2001 From: Sebastian Plesciuc Date: Mon, 17 Apr 2017 14:45:09 +0300 Subject: [PATCH] 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 Reviewed-By: Santiago Gimeno Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Yuta Hiroto --- ...test-cluster-worker-disconnect-on-error.js | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-cluster-worker-disconnect-on-error.js b/test/parallel/test-cluster-worker-disconnect-on-error.js index e52f7ddee60993..70d6a4df2a950c 100644 --- a/test/parallel/test-cluster-worker-disconnect-on-error.js +++ b/test/parallel/test-cluster-worker-disconnect-on-error.js @@ -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(); + })); })); }