From 2e5188de928946c81266b149887d9b31111a5267 Mon Sep 17 00:00:00 2001 From: Tarun Batra Date: Mon, 17 Apr 2017 02:21:48 +0530 Subject: [PATCH] test: remove common.PORT from multiple tests PR-URL: https://github.com/nodejs/node/pull/12451 Ref: https://github.com/nodejs/node/issues/12376 Reviewed-By: Santiago Gimeno Reviewed-By: Luigi Pinca Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-cluster-master-error.js | 2 +- test/parallel/test-cluster-master-kill.js | 2 +- test/parallel/test-cluster-net-send.js | 4 ++-- test/parallel/test-cluster-rr-domain-listen.js | 2 +- test/parallel/test-cluster-rr-ref.js | 2 +- test/parallel/test-cluster-shared-leak.js | 8 +++----- test/parallel/test-cluster-worker-no-exit.js | 4 ++-- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-cluster-master-error.js b/test/parallel/test-cluster-master-error.js index ce5b8e57044830..0a2dcc43faa3f6 100644 --- a/test/parallel/test-cluster-master-error.js +++ b/test/parallel/test-cluster-master-error.js @@ -31,7 +31,7 @@ if (cluster.isWorker) { const http = require('http'); http.Server(() => { - }).listen(common.PORT, '127.0.0.1'); + }).listen(0, '127.0.0.1'); } else if (process.argv[2] === 'cluster') { diff --git a/test/parallel/test-cluster-master-kill.js b/test/parallel/test-cluster-master-kill.js index a0550b8998814c..f195599b3f25aa 100644 --- a/test/parallel/test-cluster-master-kill.js +++ b/test/parallel/test-cluster-master-kill.js @@ -28,7 +28,7 @@ if (cluster.isWorker) { // keep the worker alive const http = require('http'); - http.Server().listen(common.PORT, '127.0.0.1'); + http.Server().listen(0, '127.0.0.1'); } else if (process.argv[2] === 'cluster') { diff --git a/test/parallel/test-cluster-net-send.js b/test/parallel/test-cluster-net-send.js index 98c7bd2e66192d..bf0ee4e4f47f37 100644 --- a/test/parallel/test-cluster-net-send.js +++ b/test/parallel/test-cluster-net-send.js @@ -67,8 +67,8 @@ if (process.argv[2] !== 'child') { socketConnected(); }); - server.listen(common.PORT, function() { - socket = net.connect(common.PORT, '127.0.0.1', socketConnected); + server.listen(0, function() { + socket = net.connect(server.address().port, '127.0.0.1', socketConnected); }); process.on('disconnect', function() { diff --git a/test/parallel/test-cluster-rr-domain-listen.js b/test/parallel/test-cluster-rr-domain-listen.js index b1b4f3f5a835a4..4b511d0d204d9e 100644 --- a/test/parallel/test-cluster-rr-domain-listen.js +++ b/test/parallel/test-cluster-rr-domain-listen.js @@ -32,7 +32,7 @@ if (cluster.isWorker) { d.run(common.noop); const http = require('http'); - http.Server(common.noop).listen(common.PORT, '127.0.0.1'); + http.Server(common.noop).listen(0, '127.0.0.1'); } else if (cluster.isMaster) { diff --git a/test/parallel/test-cluster-rr-ref.js b/test/parallel/test-cluster-rr-ref.js index 19420fed83f9f1..cf5e4f346bf7e2 100644 --- a/test/parallel/test-cluster-rr-ref.js +++ b/test/parallel/test-cluster-rr-ref.js @@ -10,7 +10,7 @@ if (cluster.isMaster) { }); } else { const server = net.createServer(common.mustNotCall()); - server.listen(common.PORT, function() { + server.listen(0, function() { server.unref(); server.ref(); server.close(function() { diff --git a/test/parallel/test-cluster-shared-leak.js b/test/parallel/test-cluster-shared-leak.js index d578ee6373f3b6..a7b3023f3ed3ba 100644 --- a/test/parallel/test-cluster-shared-leak.js +++ b/test/parallel/test-cluster-shared-leak.js @@ -13,10 +13,10 @@ if (cluster.isMaster) { let conn, worker2; const worker1 = cluster.fork(); - worker1.on('message', common.mustCall(function() { + worker1.on('listening', common.mustCall(function(address) { worker2 = cluster.fork(); worker2.on('online', function() { - conn = net.connect(common.PORT, common.mustCall(function() { + conn = net.connect(address.port, common.mustCall(function() { worker1.disconnect(); worker2.disconnect(); })); @@ -48,6 +48,4 @@ const server = net.createServer(function(c) { c.end('bye'); }); -server.listen(common.PORT, function() { - process.send('listening'); -}); +server.listen(0); diff --git a/test/parallel/test-cluster-worker-no-exit.js b/test/parallel/test-cluster-worker-no-exit.js index db6f0fc7a033bc..7dbe9fcb375caf 100644 --- a/test/parallel/test-cluster-worker-no-exit.js +++ b/test/parallel/test-cluster-worker-no-exit.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const cluster = require('cluster'); const net = require('net'); @@ -55,7 +55,7 @@ if (cluster.isMaster) { success = true; }); - }).listen(common.PORT, function() { + }).listen(0, function() { const port = this.address().port; worker = cluster.fork()