Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bdedf3a

Browse files
committedMar 27, 2021
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 bdedf3a

16 files changed

+22
-11
lines changed
 

‎test/common/inspector-helper.js

+2-1
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

+1-1
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

+1
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

+1
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

+1-1
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

+1
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

+2-2
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

+1-1
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

+3-1
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

+2-2
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
}));

‎test/parallel/test-tls-client-getephemeralkeyinfo.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function test(size, type, name, cipher) {
4040
server.listen(0, '127.0.0.1', common.mustCall(() => {
4141
const client = tls.connect({
4242
port: server.address().port,
43+
family: 4,
4344
rejectUnauthorized: false
4445
}, common.mustCall(function() {
4546
const ekeyinfo = client.getEphemeralKeyInfo();

‎test/parallel/test-tls-client-mindhsize.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function test(size, err, next) {
4141
const client = tls.connect({
4242
minDHSize: 2048,
4343
port: this.address().port,
44+
family: 4,
4445
rejectUnauthorized: false
4546
}, function() {
4647
nsuccess++;

‎test/parallel/test-tls-wrap-econnreset-localaddress.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const server = net.createServer((c) => {
1616
let errored = false;
1717
tls.connect({
1818
port: port,
19+
family: 4,
1920
localAddress: common.localhostIPv4
2021
}, common.localhostIPv4)
2122
.once('error', common.mustCall((e) => {

‎test/sequential/test-https-connect-localport.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const assert = require('assert');
2323
host: 'localhost',
2424
pathname: '/',
2525
port,
26-
family: 4,
26+
// family: 4,
2727
localPort: common.PORT,
2828
rejectUnauthorized: false,
2929
}, common.mustCall(() => {

‎test/sequential/test-inspector-open.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function reopenAfterClose(msg) {
8080
}
8181

8282
function ping(port, callback) {
83-
net.connect(port)
83+
net.connect({ port, family: 4 })
8484
.on('connect', function() { close(this); })
8585
.on('error', function(err) { close(this, err); });
8686

‎test/sequential/test-net-connect-local-error.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ const expectedErrorCodes = ['ECONNREFUSED', 'EADDRINUSE'];
99

1010
const optionsIPv4 = {
1111
port: common.PORT,
12+
family: 4,
1213
localPort: common.PORT + 1,
1314
localAddress: common.localhostIPv4
1415
};
1516

1617
const optionsIPv6 = {
1718
host: '::1',
1819
port: common.PORT + 2,
20+
family: 6,
1921
localPort: common.PORT + 3,
2022
localAddress: '::1',
2123
};

0 commit comments

Comments
 (0)
Please sign in to comment.