From f5a051135b8764a985cf095d86d16a7008face75 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 7 Jul 2016 20:14:51 -0700 Subject: [PATCH 1/3] test: fix flaky test-https-connect-address-family Skip test if localhost does not resolve to ::1. Fixes: https://github.com/nodejs/node/issues/7288 --- .../test-https-connect-address-family.js | 51 ++++++++++++------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/test/parallel/test-https-connect-address-family.js b/test/parallel/test-https-connect-address-family.js index 5bfb7d851c5c50..7f59cb534ef4af 100644 --- a/test/parallel/test-https-connect-address-family.js +++ b/test/parallel/test-https-connect-address-family.js @@ -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'; })) + runTest(); + else + common.skip('localhost does not resolve to ::1'); }); From 00836cfa64aa269136ad02734cff11bdba51747f Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 8 Jul 2016 10:59:49 -0700 Subject: [PATCH 2/3] test: fix flaky test-tls-connect-address-family Skip test if localhost does not resolve to ::1. Fixes: https://github.com/nodejs/node/issues/7288 --- .../test-tls-connect-address-family.js | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-tls-connect-address-family.js b/test/parallel/test-tls-connect-address-family.js index 59a5c579efb281..b108ef273b6e8f 100644 --- a/test/parallel/test-tls-connect-address-family.js +++ b/test/parallel/test-tls-connect-address-family.js @@ -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'); }); From 366eaaccbed990dd6176a628b1c2ba8eec43775b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Mon, 11 Jul 2016 13:41:58 -0700 Subject: [PATCH 3/3] squash: arrow function braces --- test/parallel/test-https-connect-address-family.js | 2 +- test/parallel/test-tls-connect-address-family.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-https-connect-address-family.js b/test/parallel/test-https-connect-address-family.js index 7f59cb534ef4af..21d0bf8dc6a1a2 100644 --- a/test/parallel/test-https-connect-address-family.js +++ b/test/parallel/test-https-connect-address-family.js @@ -39,7 +39,7 @@ dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => { if (err) throw err; - if (addresses.some((val) => { return val.address === '::1'; })) + if (addresses.some((val) => val.address === '::1')) runTest(); else common.skip('localhost does not resolve to ::1'); diff --git a/test/parallel/test-tls-connect-address-family.js b/test/parallel/test-tls-connect-address-family.js index b108ef273b6e8f..6274328956e63d 100644 --- a/test/parallel/test-tls-connect-address-family.js +++ b/test/parallel/test-tls-connect-address-family.js @@ -38,7 +38,7 @@ dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => { if (err) throw err; - if (addresses.some((val) => { return val.address === '::1'; })) + if (addresses.some((val) => val.address === '::1')) runTest(); else common.skip('localhost does not resolve to ::1');