diff --git a/test/parallel/test-net-connect-options-port.js b/test/parallel/test-net-connect-options-port.js index 1225ba209281bb..b62fe945784248 100644 --- a/test/parallel/test-net-connect-options-port.js +++ b/test/parallel/test-net-connect-options-port.js @@ -83,7 +83,7 @@ const net = require('net'); } }, expectedConnections)); - server.listen(0, 'localhost', common.mustCall(() => { + server.listen(0, common.localhostIPv4, common.mustCall(() => { const port = server.address().port; // Total connections = 3 * 4(canConnect) * 6(doConnect) = 72 @@ -133,28 +133,35 @@ function doConnect(args, getCb) { } function syncFailToConnect(port, assertErr, optOnly) { + const family = 4; if (!optOnly) { // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], () => common.mustNotCall()); + const portArgFunctions = doConnect([{ port, family }], + () => common.mustNotCall()); for (const fn of portArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port})`); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([port, 'localhost'], + const portHostArgFunctions = doConnect([{ port, + host: 'localhost', + family }], () => common.mustNotCall()); for (const fn of portHostArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`); } } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], () => common.mustNotCall()); + const portOptFunctions = doConnect([{ port, family }], + () => common.mustNotCall()); for (const fn of portOptFunctions) { assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFunctions = doConnect([{ port: port, host: 'localhost' }], + const portHostOptFunctions = doConnect([{ port: port, + host: 'localhost', + family: family }], () => common.mustNotCall()); for (const fn of portHostOptFunctions) { assert.throws(fn, @@ -165,27 +172,30 @@ function syncFailToConnect(port, assertErr, optOnly) { function canConnect(port) { const noop = () => common.mustCall(); + const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], noop); + const portArgFunctions = doConnect([{ port, family }], noop); for (const fn of portArgFunctions) { fn(); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([port, 'localhost'], noop); + const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }], + noop); for (const fn of portHostArgFunctions) { fn(); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], noop); + const portOptFunctions = doConnect([{ port, family }], noop); for (const fn of portOptFunctions) { fn(); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost' }], noop); + const portHostOptFns = doConnect([{ port, host: 'localhost', family }], + noop); for (const fn of portHostOptFns) { fn(); } @@ -198,20 +208,22 @@ function asyncFailToConnect(port) { }); const dont = () => common.mustNotCall(); + const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], dont); + const portArgFunctions = doConnect([{ port, family }], dont); for (const fn of portArgFunctions) { fn().on('error', onError()); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], dont); + const portOptFunctions = doConnect([{ port, family }], dont); for (const fn of portOptFunctions) { fn().on('error', onError()); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost' }], dont); + const portHostOptFns = doConnect([{ port, host: 'localhost', family }], + dont); for (const fn of portHostOptFns) { fn().on('error', onError()); } diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index 7fb6678fe1a897..29652ec0d1c6ce 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -130,6 +130,4 @@ const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); pingPongTest(common.PIPE); pingPongTest(0); -pingPongTest(0, 'localhost'); -if (common.hasIPv6) - pingPongTest(0, '::1'); +common.hasIPv6 ? pingPongTest(0, '::1') : pingPongTest(0, '127.0.0.1'); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index 47a495c09b55ee..a3ad67d9f9ec6e 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -34,7 +34,10 @@ const remoteFamilyCandidates = ['IPv4']; if (common.hasIPv6) remoteFamilyCandidates.push('IPv6'); const server = net.createServer(common.mustCall(function(socket) { - assert.ok(remoteAddrCandidates.includes(socket.remoteAddress)); + // test to see real value in CI log + assert.match(socket.remoteAddress, + /^127\.0\.0\.1$|^::1$|^::ffff:127.0.0.1$/); + // assert.ok(remoteAddrCandidates.includes(socket.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(socket.remoteFamily)); assert.ok(socket.remotePort); assert.notStrictEqual(socket.remotePort, this.address().port); diff --git a/test/parallel/test-net-writable.js b/test/parallel/test-net-writable.js index dcbb64e272b830..8036c2a13bea06 100644 --- a/test/parallel/test-net-writable.js +++ b/test/parallel/test-net-writable.js @@ -7,7 +7,9 @@ const server = net.createServer(common.mustCall(function(s) { server.close(); s.end(); })).listen(0, 'localhost', common.mustCall(function() { - const socket = net.connect(this.address().port, 'localhost'); + const socket = net.connect(this.address().port, common.hasIPv6 ? + '::1' : + '127.0.0.1'); socket.on('end', common.mustCall(() => { assert.strictEqual(socket.writable, true); socket.write('hello world'); diff --git a/test/pummel/test-net-pingpong.js b/test/pummel/test-net-pingpong.js index 09b30405da5a39..10c7a36fc4afe5 100644 --- a/test/pummel/test-net-pingpong.js +++ b/test/pummel/test-net-pingpong.js @@ -111,10 +111,8 @@ function pingPongTest(host, on_complete) { } // All are run at once and will run on different ports. -pingPongTest('localhost'); pingPongTest(null); - -if (common.hasIPv6) pingPongTest('::1'); +common.hasIPv6 ? pingPongTest('::1') : pingPongTest('127.0.0.1'); process.on('exit', function() { assert.strictEqual(tests_run, common.hasIPv6 ? 3 : 2); diff --git a/test/sequential/test-https-connect-localport.js b/test/sequential/test-https-connect-localport.js index d52c55a6d74fa0..1157e1cea7c20e 100644 --- a/test/sequential/test-https-connect-localport.js +++ b/test/sequential/test-https-connect-localport.js @@ -23,6 +23,7 @@ const assert = require('assert'); host: 'localhost', pathname: '/', port, + family: common.hasIPv6 ? 6 : 4, localPort: common.PORT, rejectUnauthorized: false, }, common.mustCall(() => {