From 947dd26826ae19db3438bab0b8fa7403309a3655 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 12 Apr 2017 15:22:15 -0700 Subject: [PATCH] test: remove common.PORT from test-cluster-basic Use of `common.PORT` in `parallel` tests is not completely safe (because the same port can be previously assigned to another test running in parallel if that test uses port `0` to get an arbitrary available port). Remove `common.PORT` from test-cluster-basic. PR-URL: https://github.com/nodejs/node/pull/12377 Reviewed-By: Richard Lau Reviewed-By: Daniel Bevenius Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-cluster-basic.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/parallel/test-cluster-basic.js b/test/parallel/test-cluster-basic.js index 89413c154ef..fa3c051ae17 100644 --- a/test/parallel/test-cluster-basic.js +++ b/test/parallel/test-cluster-basic.js @@ -14,10 +14,7 @@ function forEach(obj, fn) { if (cluster.isWorker) { - const http = require('http'); - http.Server(function() { - - }).listen(common.PORT, '127.0.0.1'); + require('http').Server(common.noop).listen(0, '127.0.0.1'); } else if (cluster.isMaster) { const checks = { @@ -109,11 +106,15 @@ if (cluster.isWorker) { case 'listening': assert.strictEqual(arguments.length, 1); - const expect = { address: '127.0.0.1', - port: common.PORT, - addressType: 4, - fd: undefined }; - assert.deepStrictEqual(arguments[0], expect); + assert.strictEqual(Object.keys(arguments[0]).length, 4); + assert.strictEqual(arguments[0].address, '127.0.0.1'); + assert.strictEqual(arguments[0].addressType, 4); + assert(arguments[0].hasOwnProperty('fd')); + assert.strictEqual(arguments[0].fd, undefined); + const port = arguments[0].port; + assert(Number.isInteger(port)); + assert(port >= 1); + assert(port <= 65535); break; default: