test: fix flaky test-*-connect-address-family

Skip tests if localhost does not resolve to ::1.

Fixes: https://github.com/nodejs/node/issues/7288
PR-URL: https://github.com/nodejs/node/pull/7605
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
Rich Trott 2016-07-07 20:14:51 -07:00
parent cfe76f2d6b
commit 2d77cba7e7
2 changed files with 63 additions and 37 deletions

View File

@ -5,19 +5,21 @@ if (!common.hasCrypto) {
return; return;
} }
const assert = require('assert');
const https = require('https');
if (!common.hasIPv6) { if (!common.hasIPv6) {
common.skip('no IPv6 support'); common.skip('no IPv6 support');
return; return;
} }
const assert = require('assert');
const https = require('https');
const dns = require('dns');
function runTest() {
const ciphers = 'AECDH-NULL-SHA'; const ciphers = 'AECDH-NULL-SHA';
https.createServer({ ciphers }, function(req, res) { https.createServer({ ciphers }, common.mustCall(function(req, res) {
this.close(); this.close();
res.end(); res.end();
}).listen(common.PORT, '::1', function() { })).listen(common.PORT, '::1', common.mustCall(function() {
const options = { const options = {
host: 'localhost', host: 'localhost',
port: common.PORT, port: common.PORT,
@ -30,4 +32,15 @@ https.createServer({ ciphers }, function(req, res) {
assert.strictEqual('::1', this.socket.remoteAddress); assert.strictEqual('::1', this.socket.remoteAddress);
this.destroy(); this.destroy();
})); }));
}));
}
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
if (err)
throw err;
if (addresses.some((val) => val.address === '::1'))
runTest();
else
common.skip('localhost does not resolve to ::1');
}); });

View File

@ -5,18 +5,20 @@ if (!common.hasCrypto) {
return; return;
} }
const assert = require('assert');
const tls = require('tls');
if (!common.hasIPv6) { if (!common.hasIPv6) {
common.skip('no IPv6 support'); common.skip('no IPv6 support');
return; return;
} }
const assert = require('assert');
const tls = require('tls');
const dns = require('dns');
function runTest() {
const ciphers = 'AECDH-NULL-SHA'; const ciphers = 'AECDH-NULL-SHA';
tls.createServer({ ciphers }, function() { tls.createServer({ ciphers }, common.mustCall(function() {
this.close(); this.close();
}).listen(common.PORT, '::1', function() { })).listen(common.PORT, '::1', common.mustCall(function() {
const options = { const options = {
host: 'localhost', host: 'localhost',
port: common.PORT, port: common.PORT,
@ -29,4 +31,15 @@ tls.createServer({ ciphers }, function() {
assert.strictEqual('::1', this.remoteAddress); assert.strictEqual('::1', this.remoteAddress);
this.destroy(); this.destroy();
})); }));
}));
}
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
if (err)
throw err;
if (addresses.some((val) => val.address === '::1'))
runTest();
else
common.skip('localhost does not resolve to ::1');
}); });