diff --git a/test/parallel/test-net-better-error-messages-port-hostname.js b/test/parallel/test-net-better-error-messages-port-hostname.js index 14f84eb15b1..04974908c91 100644 --- a/test/parallel/test-net-better-error-messages-port-hostname.js +++ b/test/parallel/test-net-better-error-messages-port-hostname.js @@ -3,12 +3,13 @@ const common = require('../common'); const net = require('net'); const assert = require('assert'); -const c = net.createConnection(common.PORT, '***'); +// Using port 0 as hostname used is already invalid. +const c = net.createConnection(0, '***'); c.on('connect', common.mustNotCall()); c.on('error', common.mustCall(function(e) { assert.strictEqual(e.code, 'ENOTFOUND'); - assert.strictEqual(e.port, common.PORT); + assert.strictEqual(e.port, 0); assert.strictEqual(e.hostname, '***'); })); diff --git a/test/parallel/test-net-connect-handle-econnrefused.js b/test/parallel/test-net-connect-handle-econnrefused.js index 080c60b2d2e..569aded7bf5 100644 --- a/test/parallel/test-net-connect-handle-econnrefused.js +++ b/test/parallel/test-net-connect-handle-econnrefused.js @@ -24,13 +24,14 @@ const common = require('../common'); const net = require('net'); const assert = require('assert'); - -// Hopefully nothing is running on common.PORT -const c = net.createConnection(common.PORT); +const server = net.createServer(); +server.listen(0); +const port = server.address().port; +const c = net.createConnection(port); c.on('connect', common.mustNotCall()); -c.on('error', common.mustCall(function(e) { - console.error('couldn\'t connect.'); +c.on('error', common.mustCall((e) => { assert.strictEqual('ECONNREFUSED', e.code); })); +server.close(); diff --git a/test/parallel/test-net-connect-immediate-destroy.js b/test/parallel/test-net-connect-immediate-destroy.js index 9a029b5d605..3ca58c356b4 100644 --- a/test/parallel/test-net-connect-immediate-destroy.js +++ b/test/parallel/test-net-connect-immediate-destroy.js @@ -2,7 +2,10 @@ const common = require('../common'); const net = require('net'); -const socket = net.connect(common.PORT, common.localhostIPv4, - common.mustNotCall()); +const server = net.createServer(); +server.listen(0); +const port = server.address().port; +const socket = net.connect(port, common.localhostIPv4, common.mustNotCall()); socket.on('error', common.mustNotCall()); +server.close(); socket.destroy(); diff --git a/test/parallel/test-net-connect-immediate-finish.js b/test/parallel/test-net-connect-immediate-finish.js index 340faffcb69..209b90d71d0 100644 --- a/test/parallel/test-net-connect-immediate-finish.js +++ b/test/parallel/test-net-connect-immediate-finish.js @@ -26,7 +26,7 @@ const net = require('net'); const client = net.connect({host: '***', port: common.PORT}); -client.once('error', common.mustCall(function(err) { +client.once('error', common.mustCall((err) => { assert(err); assert.strictEqual(err.code, err.errno); assert.strictEqual(err.code, 'ENOTFOUND'); diff --git a/test/parallel/test-net-connect-local-error.js b/test/parallel/test-net-connect-local-error.js index f23245ac93a..e656b6cb2ac 100644 --- a/test/parallel/test-net-connect-local-error.js +++ b/test/parallel/test-net-connect-local-error.js @@ -3,17 +3,20 @@ const common = require('../common'); const assert = require('assert'); const net = require('net'); +const server = net.createServer(); +server.listen(0); +const port = server.address().port; const client = net.connect({ - port: common.PORT + 1, - localPort: common.PORT, + port: port + 1, + localPort: port, localAddress: common.localhostIPv4 }); client.on('error', common.mustCall(function onError(err) { assert.strictEqual( err.localPort, - common.PORT, - `${err.localPort} !== ${common.PORT} in ${err}` + port, + `${err.localPort} !== ${port} in ${err}` ); assert.strictEqual( err.localAddress, @@ -21,3 +24,4 @@ client.on('error', common.mustCall(function onError(err) { `${err.localAddress} !== ${common.localhostIPv4} in ${err}` ); })); +server.close(); diff --git a/test/parallel/test-net-localerror.js b/test/parallel/test-net-localerror.js index 03f8e99c5dc..845983843d8 100644 --- a/test/parallel/test-net-localerror.js +++ b/test/parallel/test-net-localerror.js @@ -20,24 +20,25 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const net = require('net'); +// Using port 0 as localPort / localAddress is already invalid. connect({ host: 'localhost', - port: common.PORT, + port: 0, localPort: 'foobar', }, /^TypeError: "localPort" option should be a number: foobar$/); connect({ host: 'localhost', - port: common.PORT, + port: 0, localAddress: 'foobar', }, /^TypeError: "localAddress" option must be a valid IP: foobar$/); function connect(opts, msg) { - assert.throws(function() { + assert.throws(() => { net.connect(opts); }, msg); } diff --git a/test/parallel/test-net-options-lookup.js b/test/parallel/test-net-options-lookup.js index 3559d84e234..c61f338b701 100644 --- a/test/parallel/test-net-options-lookup.js +++ b/test/parallel/test-net-options-lookup.js @@ -7,14 +7,15 @@ const expectedError = /^TypeError: "lookup" option should be a function$/; ['foobar', 1, {}, []].forEach((input) => connectThrows(input)); +// Using port 0 as lookup is emitted before connecting. function connectThrows(input) { const opts = { host: 'localhost', - port: common.PORT, + port: 0, lookup: input }; - assert.throws(function() { + assert.throws(() => { net.connect(opts); }, expectedError); } @@ -24,11 +25,11 @@ connectDoesNotThrow(common.noop); function connectDoesNotThrow(input) { const opts = { host: 'localhost', - port: common.PORT, + port: 0, lookup: input }; - assert.doesNotThrow(function() { + assert.doesNotThrow(() => { net.connect(opts); }); } diff --git a/test/parallel/test-net-socket-destroy-twice.js b/test/parallel/test-net-socket-destroy-twice.js index dacb91adf27..1029d7b2980 100644 --- a/test/parallel/test-net-socket-destroy-twice.js +++ b/test/parallel/test-net-socket-destroy-twice.js @@ -23,10 +23,14 @@ const common = require('../common'); const net = require('net'); -const conn = net.createConnection(common.PORT); +const server = net.createServer(); +server.listen(0); +const port = server.address().port; +const conn = net.createConnection(port); -conn.on('error', common.mustCall(function() { +conn.on('error', common.mustCall(() => { conn.destroy(); })); conn.on('close', common.mustCall()); +server.close(); diff --git a/test/parallel/test-net-better-error-messages-port.js b/test/sequential/test-net-better-error-messages-port.js similarity index 100% rename from test/parallel/test-net-better-error-messages-port.js rename to test/sequential/test-net-better-error-messages-port.js diff --git a/test/parallel/test-net-listen-shared-ports.js b/test/sequential/test-net-listen-shared-ports.js similarity index 100% rename from test/parallel/test-net-listen-shared-ports.js rename to test/sequential/test-net-listen-shared-ports.js