Browse Source

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>
v7.x
Rich Trott 8 years ago
parent
commit
2d77cba7e7
  1. 23
      test/parallel/test-https-connect-address-family.js
  2. 23
      test/parallel/test-tls-connect-address-family.js

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

@ -5,19 +5,21 @@ if (!common.hasCrypto) {
return;
}
const assert = require('assert');
const https = require('https');
if (!common.hasIPv6) {
common.skip('no IPv6 support');
return;
}
const assert = require('assert');
const https = require('https');
const dns = require('dns');
function runTest() {
const ciphers = 'AECDH-NULL-SHA';
https.createServer({ ciphers }, function(req, res) {
https.createServer({ ciphers }, common.mustCall(function(req, res) {
this.close();
res.end();
}).listen(common.PORT, '::1', function() {
})).listen(common.PORT, '::1', common.mustCall(function() {
const options = {
host: 'localhost',
port: common.PORT,
@ -30,4 +32,15 @@ https.createServer({ ciphers }, function(req, res) {
assert.strictEqual('::1', this.socket.remoteAddress);
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');
});

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

@ -5,18 +5,20 @@ if (!common.hasCrypto) {
return;
}
const assert = require('assert');
const tls = require('tls');
if (!common.hasIPv6) {
common.skip('no IPv6 support');
return;
}
const assert = require('assert');
const tls = require('tls');
const dns = require('dns');
function runTest() {
const ciphers = 'AECDH-NULL-SHA';
tls.createServer({ ciphers }, function() {
tls.createServer({ ciphers }, common.mustCall(function() {
this.close();
}).listen(common.PORT, '::1', function() {
})).listen(common.PORT, '::1', common.mustCall(function() {
const options = {
host: 'localhost',
port: common.PORT,
@ -29,4 +31,15 @@ tls.createServer({ ciphers }, function() {
assert.strictEqual('::1', this.remoteAddress);
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');
});

Loading…
Cancel
Save