Skip to content

Commit e56db14

Browse files
Trottcjihrig
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]> Conflicts: test/parallel/test-https-connect-address-family.js test/parallel/test-tls-connect-address-family.js
1 parent 5f3ab3f commit e56db14

File tree

2 files changed

+71
-35
lines changed

2 files changed

+71
-35
lines changed
Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
4-
const https = require('https');
3+
if (!common.hasCrypto) {
4+
common.skip('missing crypto');
5+
return;
6+
}
57

68
if (!common.hasIPv6) {
79
common.skip('no IPv6 support');
810
return;
911
}
1012

11-
const ciphers = 'AECDH-NULL-SHA';
12-
https.createServer({ ciphers }, function(req, res) {
13-
this.close();
14-
res.end();
15-
}).listen(common.PORT, '::1', function() {
16-
const options = {
17-
host: 'localhost',
18-
port: common.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();
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+
}));
2735
}));
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');
2846
});
Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
4-
const tls = require('tls');
3+
if (!common.hasCrypto) {
4+
common.skip('missing crypto');
5+
return;
6+
}
57

68
if (!common.hasIPv6) {
79
common.skip('no IPv6 support');
810
return;
911
}
1012

11-
const ciphers = 'AECDH-NULL-SHA';
12-
tls.createServer({ ciphers }, function() {
13-
this.close();
14-
}).listen(common.PORT, '::1', function() {
15-
const options = {
16-
host: 'localhost',
17-
port: common.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();
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+
}));
2634
}));
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');
2745
});

0 commit comments

Comments
 (0)