Skip to content

Commit 3dbcc3d

Browse files
TrottMylesBorins
authored andcommitted
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 733233d commit 3dbcc3d

File tree

2 files changed

+63
-35
lines changed

2 files changed

+63
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
4-
const https = require('https');
53

64
if (!common.hasIPv6) {
75
common.skip('no IPv6 support');
86
return;
97
}
108

11-
const ciphers = 'AECDH-NULL-SHA';
12-
https.createServer({ ciphers }, function(req, res) {
13-
this.close();
14-
res.end();
15-
}).listen(0, '::1', function() {
16-
const options = {
17-
host: 'localhost',
18-
port: this.address().port,
19-
family: 6,
20-
ciphers: ciphers,
21-
rejectUnauthorized: false,
22-
};
23-
// Will fail with ECONNREFUSED if the address family is not honored.
24-
https.get(options, common.mustCall(function() {
25-
assert.strictEqual('::1', this.socket.remoteAddress);
26-
this.destroy();
9+
const assert = require('assert');
10+
const https = require('https');
11+
const dns = require('dns');
12+
13+
function runTest() {
14+
const ciphers = 'AECDH-NULL-SHA';
15+
https.createServer({ ciphers }, common.mustCall(function(req, res) {
16+
this.close();
17+
res.end();
18+
})).listen(common.PORT, '::1', common.mustCall(function() {
19+
const options = {
20+
host: 'localhost',
21+
port: common.PORT,
22+
family: 6,
23+
ciphers: ciphers,
24+
rejectUnauthorized: false,
25+
};
26+
// Will fail with ECONNREFUSED if the address family is not honored.
27+
https.get(options, common.mustCall(function() {
28+
assert.strictEqual('::1', this.socket.remoteAddress);
29+
this.destroy();
30+
}));
2731
}));
32+
}
33+
34+
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
35+
if (err)
36+
throw err;
37+
38+
if (addresses.some((val) => val.address === '::1'))
39+
runTest();
40+
else
41+
common.skip('localhost does not resolve to ::1');
2842
});
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
4-
const tls = require('tls');
53

64
if (!common.hasIPv6) {
75
common.skip('no IPv6 support');
86
return;
97
}
108

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

0 commit comments

Comments
 (0)