Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: fix flaky test-https-connect-address-family
Skip test if localhost does not resolve to ::1.

Fixes: #7288
  • Loading branch information
Trott committed Jul 11, 2016
commit f5a051135b8764a985cf095d86d16a7008face75
51 changes: 32 additions & 19 deletions test/parallel/test-https-connect-address-family.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,42 @@ if (!common.hasCrypto) {
return;
}

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

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

const ciphers = 'AECDH-NULL-SHA';
https.createServer({ ciphers }, function(req, res) {
this.close();
res.end();
}).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.
https.get(options, common.mustCall(function() {
assert.strictEqual('::1', this.socket.remoteAddress);
this.destroy();
const assert = require('assert');
const https = require('https');
const dns = require('dns');

function runTest() {
const ciphers = 'AECDH-NULL-SHA';
https.createServer({ ciphers }, common.mustCall(function(req, res) {
this.close();
res.end();
})).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.
https.get(options, common.mustCall(function() {
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) => { return val.address === '::1'; }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to do

addresses.some((val) => val.address === '::1')

Copy link
Member Author

@Trott Trott Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I was going with the de facto standard in the project code as it exists, but it looks like you are correct. There are over 150 instances where the braces are already omitted and only around 20 cases where there are braces included even though they can be removed.

So, yeah, I'll remove these.

runTest();
else
common.skip('localhost does not resolve to ::1');
});