Skip to content

Commit

Permalink
Fix test suite.
Browse files Browse the repository at this point in the history
Explanations:
-------------
test/parallel/test-cluster-message.js: add `family: 4` to `connect` because without it will default to `localhost` which could resolve to `::1` if IPv6 is available, while server listen address is hardcoded legacy IPv4.
test/parallel/test-http-localaddress.js: add `family: 4,` to `connect` because `localhost` could resolve to `::1` if IPv6 is available, while server listen address is hardcoded legacy IPv4.
test/parallel/test-http-upgrade-client.js: add `family: 4,` to `http.get` because `http.get` without specified host uses `localhost` which could resolve to `::1` if IPv6 is available, while server listen address is hardcoded legacy IPv4.
test/parallel/test-http2-connect-options.js: add `family: 4` to `http2.connect` `options` because `localhost` might resolve to `::1` if IPv6 is available, causing `EINVAL` when binding to `127.0.0.2`, and server listen address is hardcoded legacy IPv4.
test/parallel/test-https-localaddress.js: add `family: 4` to `https.request` `options` because `localhost` might resolve to `::1` if IPv6 is available, causing `EINVAL` when binding to `127.0.0.2`, and server listen address is hardcoded legacy IPv4.

test/common/inspector-helper.js: add `family: 4` to `http.get` options to make sure to connect via legacy IPv4 `localhost`, because inspector by default listens on legacy IPv4 `localhost`.
	Fixes:
		test/parallel/test-inspect-async-hook-setup-at-inspect.js
		test/parallel/test-inspector-esm.js
		test/parallel/test-inspector-inspect-brk-node.js
		test/parallel/test-inspector-multisession-ws.js
		test/parallel/test-inspector-reported-host.js
		test/parallel/test-inspector-wait-for-connection.js
		test/parallel/test-inspector-waiting-for-disconnect.js
		test/sequential/test-inspector.js
		test/sequential/test-inspector-async-hook-setup-at-inspect-brk.js
		test/sequential/test-inspector-async-hook-setup-at-signal.js
		test/sequential/test-inspector-async-stack-traces-promise-then.js
		test/sequential/test-inspector-async-stack-traces-set-interval.js
		test/sequential/test-inspector-break-e.js
		test/sequential/test-inspector-break-when-eval.js
		test/sequential/test-inspector-console.js
		test/sequential/test-inspector-debug-brk-flag.js
		test/sequential/test-inspector-debug-end.js
		test/sequential/test-inspector-exception.js
		test/sequential/test-inspector-not-blocked-on-idle.js
		test/sequential/test-inspector-scriptparsed-context.js
		test/sequential/test-inspector-stop-profile-after-done.js
		test/sequential/test-inspector-stress-http.js

test/parallel/test-net-dns-lookup.js: listen on `common.localhostIPv4` and add `family: 4` to `connect` to force legacy IPv4, because it is required by the assertion tests. Could be changed to DualStack compatibility by using `assert.match(ip, /^(127\.0\.0\.1|::1)$/);` and `assert.match(type.toString, /^(4|6)$/);`.
test/parallel/test-net-remote-address-port.js: add `::1` to `remoteAddrCandidates`. Why does this fix it?
test/parallel/test-tcp-wrap-listen.js: add ternary test with `hasIPv6` and use `bind` or `bind6` accordingly.
test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js: add `family: 4` to `connect` because it will default to localhost being `::1` if IPv6 is available, and listen address is hardcoded to be legacy IPv4 address for `localhost`.
test/parallel/test-tls-client-getephemeralkeyinfo.js: add `family: 4` to `connect` because without it will default to `localhost` which could resolve to `::1` if IPv6 is available, while server listen address is hardcoded legacy IPv4.
test/parallel/test-tls-client-mindhsize.js: add `family: 4` to `connect` because without it will default to `localhost` which could resolve to `::1` if IPv6 is available, while server listen address is hardcoded legacy IPv4.
test/parallel/test-tls-wrap-econnreset-localaddress.js: add `family: 4` to `connect` because without it will default to `localhost` which could resolve to `::1` if IPv6 is available, while server listen address is hardcoded legacy IPv4.
test/sequential/test-https-connect-localport.js: remove `family: 4` from connect because listen uses `localhost` which maybe resolves to `::1`? NEEDS TESTING! If it fails --> force legacy IPv4 with `common.localhostIPv4`.
test/sequential/test-inspector-open.js: add `family: 4` to `connect` because without it will default to `localhost` which could resolve to `::1` if IPv6 is available, while inspector is listening on legacy IPv4 `localhost` by default.
test/sequential/test-net-connect-local-error.js: add `family: 4` to `optionsIPv4` and `family: 6` to `optionsIPv6`, because it seems connecting on IPv4 will default to `localhost` which then resolves to `::1` if IPv6 is available and will cause an error.
  • Loading branch information
treysis committed Mar 27, 2021
1 parent 90a5e93 commit 5f24bef
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class NodeInstance extends EventEmitter {
console.log('[test]', `Testing ${path}`);
const headers = hostHeaderValue ? { 'Host': hostHeaderValue } : null;
return this.portPromise.then((port) => new Promise((resolve, reject) => {
const req = http.get({ host, port, path, headers }, (res) => {
const req = http.get({ host, port, family: 4, path, headers }, (res) => {
let response = '';
res.setEncoding('utf8');
res
Expand All @@ -419,6 +419,7 @@ class NodeInstance extends EventEmitter {
const port = await this.portPromise;
return http.get({
port,
family: 4,
path: parseURL(devtoolsUrl).path,
headers: {
'Connection': 'Upgrade',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ if (cluster.isWorker) {
// When a TCP server is listening in the worker connect to it
worker.on('listening', function(address) {

client = net.connect(address.port, function() {
client = net.connect({ port: address.port, family: 4 }, function() {
// Send message to worker.
worker.send('message from primary');
});
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const server = http.createServer((req, res) => {
server.listen(0, '127.0.0.1', () => {
const options = { host: 'localhost',
port: server.address().port,
family: 4,
path: '/',
method: 'GET',
localAddress: '127.0.0.2' };
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http-upgrade-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
headers.forEach(function(h) {
const req = http.get({
port: port,
family: 4,
headers: h
});
let sawUpgrade = false;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-connect-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const server = http2.createServer((req, res) => {
});

server.listen(0, '127.0.0.1', common.mustCall(() => {
const options = { localAddress: '127.0.0.2' };
const options = { localAddress: '127.0.0.2', family: 4 };

const client = http2.connect(
'http://localhost:' + server.address().port,
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-https-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ server.listen(0, '127.0.0.1', function() {
const options = {
host: 'localhost',
port: this.address().port,
family: 4,
path: '/',
method: 'GET',
localAddress: '127.0.0.2',
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-net-dns-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const server = net.createServer(function(client) {
server.close();
});

server.listen(0, '127.0.0.1', common.mustCall(function() {
net.connect(this.address().port, 'localhost')
server.listen(0, common.localhostIPv4, common.mustCall(function() {
net.connect({ port: this.address().port, host: 'localhost', family: 4 })
.on('lookup', common.mustCall(function(err, ip, type, host) {
assert.strictEqual(err, null);
assert.strictEqual(ip, '127.0.0.1');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-net-remote-address-port.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const net = require('net');
let conns_closed = 0;

const remoteAddrCandidates = [ common.localhostIPv4 ];
if (common.hasIPv6) remoteAddrCandidates.push('::ffff:127.0.0.1');
if (common.hasIPv6) remoteAddrCandidates.push('::1', '::ffff:127.0.0.1');

const remoteFamilyCandidates = ['IPv4'];
if (common.hasIPv6) remoteFamilyCandidates.push('IPv6');
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-tcp-wrap-listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const {

const server = new TCP(TCPConstants.SOCKET);

const r = server.bind('0.0.0.0', 0);
const r = (common.hasIPv6 ?
server.bind6('::', 0) :
server.bind('0.0.0.0', 0));
assert.strictEqual(r, 0);
let port = {};
server.getsockname(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ server.listen(0, common.localhostIPv4, common.mustCall(() => {
const countdown = new Countdown(2, () => server.close());

{
const client = net.connect({ port: server.address().port });
const client = net.connect({ port: server.address().port, family: 4 });
client.on('end', () => countdown.dec());
}

{
const client = net.connect({ port: server.address().port });
const client = net.connect({ port: server.address().port, family: 4 });
client.on('end', () => countdown.dec());
}
}));
1 change: 1 addition & 0 deletions test/parallel/test-tls-client-getephemeralkeyinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function test(size, type, name, cipher) {
server.listen(0, '127.0.0.1', common.mustCall(() => {
const client = tls.connect({
port: server.address().port,
family: 4,
rejectUnauthorized: false
}, common.mustCall(function() {
const ekeyinfo = client.getEphemeralKeyInfo();
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-tls-client-mindhsize.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function test(size, err, next) {
const client = tls.connect({
minDHSize: 2048,
port: this.address().port,
family: 4,
rejectUnauthorized: false
}, function() {
nsuccess++;
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-tls-wrap-econnreset-localaddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const server = net.createServer((c) => {
let errored = false;
tls.connect({
port: port,
family: 4,
localAddress: common.localhostIPv4
}, common.localhostIPv4)
.once('error', common.mustCall((e) => {
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-https-connect-localport.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const assert = require('assert');
host: 'localhost',
pathname: '/',
port,
family: 4,
//family: 4,
localPort: common.PORT,
rejectUnauthorized: false,
}, common.mustCall(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-inspector-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function reopenAfterClose(msg) {
}

function ping(port, callback) {
net.connect(port)
net.connect({ port, family: 4 })
.on('connect', function() { close(this); })
.on('error', function(err) { close(this, err); });

Expand Down
2 changes: 2 additions & 0 deletions test/sequential/test-net-connect-local-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ const expectedErrorCodes = ['ECONNREFUSED', 'EADDRINUSE'];

const optionsIPv4 = {
port: common.PORT,
family: 4,
localPort: common.PORT + 1,
localAddress: common.localhostIPv4
};

const optionsIPv6 = {
host: '::1',
port: common.PORT + 2,
family: 6,
localPort: common.PORT + 3,
localAddress: '::1',
};
Expand Down

0 comments on commit 5f24bef

Please sign in to comment.