Skip to content

Commit 2d77cba

Browse files
committed
test: fix flaky test-*-connect-address-family
Skip tests if localhost does not resolve to ::1. Fixes: #7288 PR-URL: #7605 Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent cfe76f2 commit 2d77cba

File tree

2 files changed

+63
-37
lines changed

2 files changed

+63
-37
lines changed

test/parallel/test-https-connect-address-family.js

+32-19
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,42 @@ if (!common.hasCrypto) {
55
return;
66
}
77

8-
const assert = require('assert');
9-
const https = require('https');
10-
118
if (!common.hasIPv6) {
129
common.skip('no IPv6 support');
1310
return;
1411
}
1512

16-
const ciphers = 'AECDH-NULL-SHA';
17-
https.createServer({ ciphers }, function(req, res) {
18-
this.close();
19-
res.end();
20-
}).listen(common.PORT, '::1', function() {
21-
const options = {
22-
host: 'localhost',
23-
port: common.PORT,
24-
family: 6,
25-
ciphers: ciphers,
26-
rejectUnauthorized: false,
27-
};
28-
// Will fail with ECONNREFUSED if the address family is not honored.
29-
https.get(options, common.mustCall(function() {
30-
assert.strictEqual('::1', this.socket.remoteAddress);
31-
this.destroy();
13+
const assert = require('assert');
14+
const https = require('https');
15+
const dns = require('dns');
16+
17+
function runTest() {
18+
const ciphers = 'AECDH-NULL-SHA';
19+
https.createServer({ ciphers }, common.mustCall(function(req, res) {
20+
this.close();
21+
res.end();
22+
})).listen(common.PORT, '::1', common.mustCall(function() {
23+
const options = {
24+
host: 'localhost',
25+
port: common.PORT,
26+
family: 6,
27+
ciphers: ciphers,
28+
rejectUnauthorized: false,
29+
};
30+
// Will fail with ECONNREFUSED if the address family is not honored.
31+
https.get(options, common.mustCall(function() {
32+
assert.strictEqual('::1', this.socket.remoteAddress);
33+
this.destroy();
34+
}));
3235
}));
36+
}
37+
38+
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
39+
if (err)
40+
throw err;
41+
42+
if (addresses.some((val) => val.address === '::1'))
43+
runTest();
44+
else
45+
common.skip('localhost does not resolve to ::1');
3346
});

test/parallel/test-tls-connect-address-family.js

+31-18
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,41 @@ if (!common.hasCrypto) {
55
return;
66
}
77

8-
const assert = require('assert');
9-
const tls = require('tls');
10-
118
if (!common.hasIPv6) {
129
common.skip('no IPv6 support');
1310
return;
1411
}
1512

16-
const ciphers = 'AECDH-NULL-SHA';
17-
tls.createServer({ ciphers }, function() {
18-
this.close();
19-
}).listen(common.PORT, '::1', function() {
20-
const options = {
21-
host: 'localhost',
22-
port: common.PORT,
23-
family: 6,
24-
ciphers: ciphers,
25-
rejectUnauthorized: false,
26-
};
27-
// Will fail with ECONNREFUSED if the address family is not honored.
28-
tls.connect(options).once('secureConnect', common.mustCall(function() {
29-
assert.strictEqual('::1', this.remoteAddress);
30-
this.destroy();
13+
const assert = require('assert');
14+
const tls = require('tls');
15+
const dns = require('dns');
16+
17+
function runTest() {
18+
const ciphers = 'AECDH-NULL-SHA';
19+
tls.createServer({ ciphers }, common.mustCall(function() {
20+
this.close();
21+
})).listen(common.PORT, '::1', common.mustCall(function() {
22+
const options = {
23+
host: 'localhost',
24+
port: common.PORT,
25+
family: 6,
26+
ciphers: ciphers,
27+
rejectUnauthorized: false,
28+
};
29+
// Will fail with ECONNREFUSED if the address family is not honored.
30+
tls.connect(options).once('secureConnect', common.mustCall(function() {
31+
assert.strictEqual('::1', this.remoteAddress);
32+
this.destroy();
33+
}));
3134
}));
35+
}
36+
37+
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
38+
if (err)
39+
throw err;
40+
41+
if (addresses.some((val) => val.address === '::1'))
42+
runTest();
43+
else
44+
common.skip('localhost does not resolve to ::1');
3245
});

0 commit comments

Comments
 (0)