Skip to content

Commit

Permalink
dns: test suite fixes for CI
Browse files Browse the repository at this point in the history
PR-URL: #39987
Fixes: #31566
Refs: #6307
Refs: #20710
Refs: #38099
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
treysis authored and nodejs-github-bot committed Sep 12, 2021
1 parent 73c32d5 commit 2d7466e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
36 changes: 24 additions & 12 deletions test/parallel/test-net-connect-options-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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();
}
Expand All @@ -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());
}
Expand Down
4 changes: 1 addition & 3 deletions test/parallel/test-net-pingpong.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
5 changes: 4 additions & 1 deletion test/parallel/test-net-remote-address-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-net-writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 1 addition & 3 deletions test/pummel/test-net-pingpong.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/sequential/test-https-connect-localport.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const assert = require('assert');
host: 'localhost',
pathname: '/',
port,
family: common.hasIPv6 ? 6 : 4,
localPort: common.PORT,
rejectUnauthorized: false,
}, common.mustCall(() => {
Expand Down

0 comments on commit 2d7466e

Please sign in to comment.