From 3deee057b3f9eed40290766ee971c9237aecec59 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 20 Feb 2020 21:50:07 -0800 Subject: [PATCH] test: remove common.PORT from assorted pummel tests Use port "0" for an OS-provided open port instead of common.PORT. PR-URL: https://github.com/nodejs/node/pull/31897 Reviewed-By: Michael Dawson Reviewed-By: Denys Otrishko --- test/pummel/test-http-many-keep-alive-connections.js | 6 +++--- test/pummel/test-http-upload-timeout.js | 6 +++--- test/pummel/test-https-large-response.js | 4 ++-- test/pummel/test-https-no-reader.js | 4 ++-- test/pummel/test-net-pingpong-delay.js | 8 ++++---- test/pummel/test-net-timeout2.js | 4 ++-- test/pummel/test-regress-GH-892.js | 4 ++-- test/pummel/test-tls-throttle.js | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/pummel/test-http-many-keep-alive-connections.js b/test/pummel/test-http-many-keep-alive-connections.js index 59eccc328d5f03..9a7083a8ae66cb 100644 --- a/test/pummel/test-http-many-keep-alive-connections.js +++ b/test/pummel/test-http-many-keep-alive-connections.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 http = require('http'); @@ -40,9 +40,9 @@ server.once('connection', function(c) { connection = c; }); -server.listen(common.PORT, function connect() { +server.listen(0, function connect() { const request = http.get({ - port: common.PORT, + port: server.address().port, path: '/', headers: { 'Connection': 'Keep-alive' diff --git a/test/pummel/test-http-upload-timeout.js b/test/pummel/test-http-upload-timeout.js index 2c1cbf61988ec6..c3ec3ad19d5d37 100644 --- a/test/pummel/test-http-upload-timeout.js +++ b/test/pummel/test-http-upload-timeout.js @@ -23,7 +23,7 @@ // This tests setTimeout() by having multiple clients connecting and sending // data in random intervals. Clients are also randomly disconnecting until there // are no more clients left. If no false timeout occurs, this test has passed. -const common = require('../common'); +require('../common'); const http = require('http'); const server = http.createServer(); let connections = 0; @@ -44,13 +44,13 @@ server.on('request', function(req, res) { req.resume(); }); -server.listen(common.PORT, '127.0.0.1', function() { +server.listen(0, '127.0.0.1', function() { for (let i = 0; i < 10; i++) { connections++; setTimeout(function() { const request = http.request({ - port: common.PORT, + port: server.address().port, method: 'POST', path: '/' }); diff --git a/test/pummel/test-https-large-response.js b/test/pummel/test-https-large-response.js index d72fd2a65ba877..acf442d2541d1a 100644 --- a/test/pummel/test-https-large-response.js +++ b/test/pummel/test-https-large-response.js @@ -43,9 +43,9 @@ const server = https.createServer(options, common.mustCall(function(req, res) { res.end(body); })); -server.listen(common.PORT, common.mustCall(function() { +server.listen(0, common.mustCall(function() { https.get({ - port: common.PORT, + port: server.address().port, rejectUnauthorized: false }, common.mustCall(function(res) { console.log('response!'); diff --git a/test/pummel/test-https-no-reader.js b/test/pummel/test-https-no-reader.js index 31d2bfa2d3ca34..63db032d0b6144 100644 --- a/test/pummel/test-https-no-reader.js +++ b/test/pummel/test-https-no-reader.js @@ -43,10 +43,10 @@ const server = https.createServer(options, function(req, res) { res.end(); }); -server.listen(common.PORT, function() { +server.listen(0, function() { const req = https.request({ method: 'POST', - port: common.PORT, + port: server.address().port, rejectUnauthorized: false }, function(res) { res.read(0); diff --git a/test/pummel/test-net-pingpong-delay.js b/test/pummel/test-net-pingpong-delay.js index 392a6e0fed751e..bddcd4de72d664 100644 --- a/test/pummel/test-net-pingpong-delay.js +++ b/test/pummel/test-net-pingpong-delay.js @@ -24,7 +24,7 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); -function pingPongTest(port, host, on_complete) { +function pingPongTest(host, on_complete) { const N = 100; const DELAY = 1; let count = 0; @@ -63,8 +63,8 @@ function pingPongTest(port, host, on_complete) { }); }); - server.listen(port, host, common.mustCall(function() { - const client = net.createConnection(port, host); + server.listen(0, host, common.mustCall(function() { + const client = net.createConnection(server.address().port, host); client.setEncoding('utf8'); @@ -104,4 +104,4 @@ function pingPongTest(port, host, on_complete) { })); } -pingPongTest(common.PORT); +pingPongTest(); diff --git a/test/pummel/test-net-timeout2.js b/test/pummel/test-net-timeout2.js index 93fbe7bfab36cb..4220ef77ca6704 100644 --- a/test/pummel/test-net-timeout2.js +++ b/test/pummel/test-net-timeout2.js @@ -48,7 +48,7 @@ const server = net.createServer(function(socket) { }); -server.listen(common.PORT, function() { - const s = net.connect(common.PORT); +server.listen(0, function() { + const s = net.connect(server.address().port); s.pipe(process.stdout); }); diff --git a/test/pummel/test-regress-GH-892.js b/test/pummel/test-regress-GH-892.js index 48201807e39e56..d5e8cc0215635c 100644 --- a/test/pummel/test-regress-GH-892.js +++ b/test/pummel/test-regress-GH-892.js @@ -52,7 +52,7 @@ function makeRequest() { // more easily. Also, this is handy when using this test to // view V8 opt/deopt behavior. const args = process.execArgv.concat([ childScript, - common.PORT, + server.address().port, bytesExpected ]); const child = spawn(process.execPath, args); @@ -101,7 +101,7 @@ const server = https.Server(serverOptions, function(req, res) { }); }); -server.listen(common.PORT, function() { +server.listen(0, function() { console.log(`expecting ${bytesExpected} bytes`); makeRequest(); }); diff --git a/test/pummel/test-tls-throttle.js b/test/pummel/test-tls-throttle.js index af588dfa91fb94..da675204a1ec5c 100644 --- a/test/pummel/test-tls-throttle.js +++ b/test/pummel/test-tls-throttle.js @@ -46,9 +46,9 @@ const server = tls.Server(options, common.mustCall(function(socket) { let recvCount = 0; -server.listen(common.PORT, function() { +server.listen(0, function() { const client = tls.connect({ - port: common.PORT, + port: server.address().port, rejectUnauthorized: false });