Skip to content

Commit

Permalink
test: fix flaky test-tls-connect-address-family
Browse files Browse the repository at this point in the history
Skip test if localhost does not resolve to ::1.

Fixes: nodejs#7288
  • Loading branch information
Trott committed Jul 11, 2016
1 parent f5a0511 commit 00836cf
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions test/parallel/test-tls-connect-address-family.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,41 @@ if (!common.hasCrypto) {
return;
}

const assert = require('assert');
const tls = require('tls');

if (!common.hasIPv6) {
common.skip('no IPv6 support');
return;
}

const ciphers = 'AECDH-NULL-SHA';
tls.createServer({ ciphers }, function() {
this.close();
}).listen(common.PORT, '::1', function() {
const options = {
host: 'localhost',
port: common.PORT,
family: 6,
ciphers: ciphers,
rejectUnauthorized: false,
};
// Will fail with ECONNREFUSED if the address family is not honored.
tls.connect(options).once('secureConnect', common.mustCall(function() {
assert.strictEqual('::1', this.remoteAddress);
this.destroy();
const assert = require('assert');
const tls = require('tls');
const dns = require('dns');

function runTest() {
const ciphers = 'AECDH-NULL-SHA';
tls.createServer({ ciphers }, common.mustCall(function() {
this.close();
})).listen(common.PORT, '::1', common.mustCall(function() {
const options = {
host: 'localhost',
port: common.PORT,
family: 6,
ciphers: ciphers,
rejectUnauthorized: false,
};
// Will fail with ECONNREFUSED if the address family is not honored.
tls.connect(options).once('secureConnect', common.mustCall(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) => { return val.address === '::1'; }))
runTest();
else
common.skip('localhost does not resolve to ::1');
});

0 comments on commit 00836cf

Please sign in to comment.