summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2016-07-07 20:14:51 -0700
committerRich Trott <rtrott@gmail.com>2016-07-11 14:38:09 -0700
commit2d77cba7e7c7192b1553af0ebb28aea1499fd25e (patch)
treeb57f3abceb2e2fba324703406ced63ae81008659 /test
parentcfe76f2d6bd77d3c0a73335c9643bcd6e8dd24fc (diff)
downloadandroid-node-v8-2d77cba7e7c7192b1553af0ebb28aea1499fd25e.tar.gz
android-node-v8-2d77cba7e7c7192b1553af0ebb28aea1499fd25e.tar.bz2
android-node-v8-2d77cba7e7c7192b1553af0ebb28aea1499fd25e.zip
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>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-https-connect-address-family.js51
-rw-r--r--test/parallel/test-tls-connect-address-family.js49
2 files changed, 63 insertions, 37 deletions
diff --git a/test/parallel/test-https-connect-address-family.js b/test/parallel/test-https-connect-address-family.js
index 5bfb7d851c..21d0bf8dc6 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) => 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 59a5c579ef..6274328956 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) => val.address === '::1'))
+ runTest();
+ else
+ common.skip('localhost does not resolve to ::1');
});