Skip to content

Commit 5f24bef

Browse files
committed
Fix test suite.
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.
1 parent 90a5e93 commit 5f24bef

16 files changed

+22
-11
lines changed

test/common/inspector-helper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class NodeInstance extends EventEmitter {
393393
console.log('[test]', `Testing ${path}`);
394394
const headers = hostHeaderValue ? { 'Host': hostHeaderValue } : null;
395395
return this.portPromise.then((port) => new Promise((resolve, reject) => {
396-
const req = http.get({ host, port, path, headers }, (res) => {
396+
const req = http.get({ host, port, family: 4, path, headers }, (res) => {
397397
let response = '';
398398
res.setEncoding('utf8');
399399
res
@@ -419,6 +419,7 @@ class NodeInstance extends EventEmitter {
419419
const port = await this.portPromise;
420420
return http.get({
421421
port,
422+
family: 4,
422423
path: parseURL(devtoolsUrl).path,
423424
headers: {
424425
'Connection': 'Upgrade',

test/parallel/test-cluster-message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ if (cluster.isWorker) {
111111
// When a TCP server is listening in the worker connect to it
112112
worker.on('listening', function(address) {
113113

114-
client = net.connect(address.port, function() {
114+
client = net.connect({ port: address.port, family: 4 }, function() {
115115
// Send message to worker.
116116
worker.send('message from primary');
117117
});

test/parallel/test-http-localaddress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const server = http.createServer((req, res) => {
4242
server.listen(0, '127.0.0.1', () => {
4343
const options = { host: 'localhost',
4444
port: server.address().port,
45+
family: 4,
4546
path: '/',
4647
method: 'GET',
4748
localAddress: '127.0.0.2' };

test/parallel/test-http-upgrade-client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
6868
headers.forEach(function(h) {
6969
const req = http.get({
7070
port: port,
71+
family: 4,
7172
headers: h
7273
});
7374
let sawUpgrade = false;

test/parallel/test-http2-connect-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const server = http2.createServer((req, res) => {
2222
});
2323

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

2727
const client = http2.connect(
2828
'http://localhost:' + server.address().port,

test/parallel/test-https-localaddress.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ server.listen(0, '127.0.0.1', function() {
5252
const options = {
5353
host: 'localhost',
5454
port: this.address().port,
55+
family: 4,
5556
path: '/',
5657
method: 'GET',
5758
localAddress: '127.0.0.2',

test/parallel/test-net-dns-lookup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const server = net.createServer(function(client) {
2929
server.close();
3030
});
3131

32-
server.listen(0, '127.0.0.1', common.mustCall(function() {
33-
net.connect(this.address().port, 'localhost')
32+
server.listen(0, common.localhostIPv4, common.mustCall(function() {
33+
net.connect({ port: this.address().port, host: 'localhost', family: 4 })
3434
.on('lookup', common.mustCall(function(err, ip, type, host) {
3535
assert.strictEqual(err, null);
3636
assert.strictEqual(ip, '127.0.0.1');

test/parallel/test-net-remote-address-port.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const net = require('net');
2828
let conns_closed = 0;
2929

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

3333
const remoteFamilyCandidates = ['IPv4'];
3434
if (common.hasIPv6) remoteFamilyCandidates.push('IPv6');

test/parallel/test-tcp-wrap-listen.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const {
1414

1515
const server = new TCP(TCPConstants.SOCKET);
1616

17-
const r = server.bind('0.0.0.0', 0);
17+
const r = (common.hasIPv6 ?
18+
server.bind6('::', 0) :
19+
server.bind('0.0.0.0', 0));
1820
assert.strictEqual(r, 0);
1921
let port = {};
2022
server.getsockname(port);

test/parallel/test-timers-socket-timeout-removes-other-socket-unref-timer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ server.listen(0, common.localhostIPv4, common.mustCall(() => {
3232
const countdown = new Countdown(2, () => server.close());
3333

3434
{
35-
const client = net.connect({ port: server.address().port });
35+
const client = net.connect({ port: server.address().port, family: 4 });
3636
client.on('end', () => countdown.dec());
3737
}
3838

3939
{
40-
const client = net.connect({ port: server.address().port });
40+
const client = net.connect({ port: server.address().port, family: 4 });
4141
client.on('end', () => countdown.dec());
4242
}
4343
}));

0 commit comments

Comments
 (0)