From 34cc8b941117cf0775372f8ec46abf25ef7d67da Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 14 Apr 2017 22:32:45 -0700 Subject: [PATCH] test: use dynamic port in test-cluster-bind-twice Remove common.PORT from test-cluster-bind-twice to eliminate possibility that a dynamic port used in another test will collide with common.PORT. PR-URL: https://github.com/nodejs/node/pull/12418 Ref: https://github.com/nodejs/node/issues/12376 Reviewed-By: Luigi Pinca Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Benjamin Gruenbaum Reviewed-By: Gibson Fahnestock Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-cluster-bind-twice.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-cluster-bind-twice.js b/test/parallel/test-cluster-bind-twice.js index 215d4829ce215e..af3e89e05ce056 100644 --- a/test/parallel/test-cluster-bind-twice.js +++ b/test/parallel/test-cluster-bind-twice.js @@ -46,9 +46,8 @@ if (!id) { a.on('message', common.mustCall((m) => { - if (typeof m === 'object') return; - assert.strictEqual(m, 'READY'); - b.send('START'); + assert.strictEqual(m.msg, 'READY'); + b.send({msg: 'START', port: m.port}); })); b.on('message', common.mustCall((m) => { @@ -60,10 +59,10 @@ if (!id) { } else if (id === 'one') { if (cluster.isMaster) return startWorker(); - http.createServer(common.mustNotCall()) - .listen(common.PORT, common.mustCall(() => { - process.send('READY'); - })); + const server = http.createServer(common.mustNotCall()); + server.listen(0, common.mustCall(() => { + process.send({msg: 'READY', port: server.address().port}); + })); process.on('message', common.mustCall((m) => { if (m === 'QUIT') process.exit(); @@ -74,8 +73,8 @@ if (!id) { const server = http.createServer(common.mustNotCall()); process.on('message', common.mustCall((m) => { if (m === 'QUIT') process.exit(); - assert.strictEqual(m, 'START'); - server.listen(common.PORT, common.mustNotCall()); + assert.strictEqual(m.msg, 'START'); + server.listen(m.port, common.mustNotCall()); server.on('error', common.mustCall((e) => { assert.strictEqual(e.code, 'EADDRINUSE'); process.send(e.code);