From 9e5f0995bd92cdcdaff5314293ee74d934d1ef81 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 9 Sep 2015 15:06:31 -0700 Subject: [PATCH] test: split up internet dns tests For whatever reason, the CI win2012 machine was timing out on the internet test-dns file. Split out ipv4 and ipv6 specific tests to separate files so tests do not time out. (Each file is given a 60 second timeout on CI. Tests within a file are run in sequence.) PR-URL: https://github.com/nodejs/node/pull/2802 Fixes: https://github.com/nodejs/node/issues/2468 Reviewed-By: Roman Reiss --- test/internet/test-dns-ipv4.js | 203 +++++++++++++++++++ test/internet/test-dns-ipv6.js | 219 +++++++++++++++++++++ test/internet/test-dns.js | 347 --------------------------------- 3 files changed, 422 insertions(+), 347 deletions(-) create mode 100644 test/internet/test-dns-ipv4.js create mode 100644 test/internet/test-dns-ipv6.js diff --git a/test/internet/test-dns-ipv4.js b/test/internet/test-dns-ipv4.js new file mode 100644 index 00000000000000..04befca6370e1e --- /dev/null +++ b/test/internet/test-dns-ipv4.js @@ -0,0 +1,203 @@ +'use strict'; +var common = require('../common'); +var assert = require('assert'), + dns = require('dns'), + net = require('net'), + isIP = net.isIP, + isIPv4 = net.isIPv4; +var util = require('util'); + +var expected = 0, + completed = 0, + running = false, + queue = []; + +function TEST(f) { + function next() { + var f = queue.shift(); + if (f) { + running = true; + console.log(f.name); + f(done); + } + } + + function done() { + running = false; + completed++; + process.nextTick(next); + } + + expected++; + queue.push(f); + + if (!running) { + next(); + } +} + +function checkWrap(req) { + assert.ok(typeof req === 'object'); +} + +TEST(function test_resolve4(done) { + var req = dns.resolve4('www.google.com', function(err, ips) { + if (err) throw err; + + assert.ok(ips.length > 0); + + for (var i = 0; i < ips.length; i++) { + assert.ok(isIPv4(ips[i])); + } + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_reverse_ipv4(done) { + var req = dns.reverse('8.8.8.8', function(err, domains) { + if (err) throw err; + + assert.ok(domains.length > 0); + + for (var i = 0; i < domains.length; i++) { + assert.ok(domains[i]); + assert.ok(typeof domains[i] === 'string'); + } + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ipv4_explicit(done) { + var req = dns.lookup('www.google.com', 4, function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv4(ip)); + assert.strictEqual(family, 4); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ipv4_implicit(done) { + var req = dns.lookup('www.google.com', function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv4(ip)); + assert.strictEqual(family, 4); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ipv4_explicit_object(done) { + var req = dns.lookup('www.google.com', { + family: 4 + }, function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv4(ip)); + assert.strictEqual(family, 4); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ipv4_hint_addrconfig(done) { + var req = dns.lookup('www.google.com', { + hints: dns.ADDRCONFIG + }, function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv4(ip)); + assert.strictEqual(family, 4); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ip_ipv4(done) { + var req = dns.lookup('127.0.0.1', function(err, ip, family) { + if (err) throw err; + assert.strictEqual(ip, '127.0.0.1'); + assert.strictEqual(family, 4); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_localhost_ipv4(done) { + var req = dns.lookup('localhost', 4, function(err, ip, family) { + if (err) throw err; + assert.strictEqual(ip, '127.0.0.1'); + assert.strictEqual(family, 4); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_all_ipv4(done) { + var req = dns.lookup('www.google.com', {all: true, family: 4}, + function(err, ips) { + if (err) throw err; + assert.ok(Array.isArray(ips)); + assert.ok(ips.length > 0); + + ips.forEach(function(ip) { + assert.ok(isIPv4(ip.address)); + assert.strictEqual(ip.family, 4); + }); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookupservice_ip_ipv4(done) { + var req = dns.lookupService('127.0.0.1', 80, function(err, host, service) { + if (err) throw err; + assert.equal(typeof host, 'string'); + assert(host); + + /* + * Retrieve the actual HTTP service name as setup on the host currently + * running the test by reading it from /etc/services. This is not ideal, + * as the service name lookup could use another mechanism (e.g nscd), but + * it's already better than hardcoding it. + */ + var httpServiceName = common.getServiceName(80, 'tcp'); + if (!httpServiceName) { + /* + * Couldn't find service name, reverting to the most sensible default + * for port 80. + */ + httpServiceName = 'http'; + } + + assert.strictEqual(service, httpServiceName); + + done(); + }); + + checkWrap(req); +}); + +process.on('exit', function() { + console.log(completed + ' tests completed'); + assert.equal(running, false); + assert.strictEqual(expected, completed); +}); diff --git a/test/internet/test-dns-ipv6.js b/test/internet/test-dns-ipv6.js new file mode 100644 index 00000000000000..27b25f7995e630 --- /dev/null +++ b/test/internet/test-dns-ipv6.js @@ -0,0 +1,219 @@ +'use strict'; +var common = require('../common'); +var assert = require('assert'), + dns = require('dns'), + net = require('net'), + isIP = net.isIP, + isIPv6 = net.isIPv6; +var util = require('util'); + +var expected = 0, + completed = 0, + running = false, + queue = []; + +function TEST(f) { + function next() { + var f = queue.shift(); + if (f) { + running = true; + console.log(f.name); + f(done); + } + } + + function done() { + running = false; + completed++; + process.nextTick(next); + } + + expected++; + queue.push(f); + + if (!running) { + next(); + } +} + +function checkWrap(req) { + assert.ok(typeof req === 'object'); +} + +TEST(function test_resolve6(done) { + var req = dns.resolve6('ipv6.google.com', function(err, ips) { + if (err) throw err; + + assert.ok(ips.length > 0); + + for (var i = 0; i < ips.length; i++) { + assert.ok(isIPv6(ips[i])); + } + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_reverse_ipv6(done) { + var req = dns.reverse('2001:4860:4860::8888', function(err, domains) { + if (err) throw err; + + assert.ok(domains.length > 0); + + for (var i = 0; i < domains.length; i++) { + assert.ok(domains[i]); + assert.ok(typeof domains[i] === 'string'); + } + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ipv6_explicit(done) { + var req = dns.lookup('ipv6.google.com', 6, function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv6(ip)); + assert.strictEqual(family, 6); + + done(); + }); + + checkWrap(req); +}); + +/* This ends up just being too problematic to test +TEST(function test_lookup_ipv6_implicit(done) { + var req = dns.lookup('ipv6.google.com', function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv6(ip)); + assert.strictEqual(family, 6); + + done(); + }); + + checkWrap(req); +}); +*/ + +TEST(function test_lookup_ipv6_explicit_object(done) { + var req = dns.lookup('ipv6.google.com', { + family: 6 + }, function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv6(ip)); + assert.strictEqual(family, 6); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ipv6_hint(done) { + var req = dns.lookup('www.google.com', { + family: 6, + hints: dns.V4MAPPED + }, function(err, ip, family) { + if (err) { + // FreeBSD does not support V4MAPPED + if (process.platform === 'freebsd') { + assert(err instanceof Error); + assert.strictEqual(err.code, 'EAI_BADFLAGS'); + assert.strictEqual(err.hostname, 'www.google.com'); + assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message)); + done(); + return; + } else { + throw err; + } + } + assert.ok(net.isIPv6(ip)); + assert.strictEqual(family, 6); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_ip_ipv6(done) { + var req = dns.lookup('::1', function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv6(ip)); + assert.strictEqual(family, 6); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookup_all_ipv6(done) { + var req = dns.lookup('www.google.com', {all: true, family: 6}, + function(err, ips) { + if (err) throw err; + assert.ok(Array.isArray(ips)); + assert.ok(ips.length > 0); + + ips.forEach(function(ip) { + assert.ok(isIPv6(ip.address)); + assert.strictEqual(ip.family, 6); + }); + + done(); + }); + + checkWrap(req); +}); + +TEST(function test_lookupservice_ip_ipv6(done) { + var req = dns.lookupService('::1', 80, function(err, host, service) { + if (err) throw err; + assert.equal(typeof host, 'string'); + assert(host); + + /* + * Retrieve the actual HTTP service name as setup on the host currently + * running the test by reading it from /etc/services. This is not ideal, + * as the service name lookup could use another mechanism (e.g nscd), but + * it's already better than hardcoding it. + */ + var httpServiceName = common.getServiceName(80, 'tcp'); + if (!httpServiceName) { + /* + * Couldn't find service name, reverting to the most sensible default + * for port 80. + */ + httpServiceName = 'http'; + } + + assert.strictEqual(service, httpServiceName); + + done(); + }); + + checkWrap(req); +}); + +/* Disabled because it appears to be not working on linux. */ +/* TEST(function test_lookup_localhost_ipv6(done) { + var req = dns.lookup('localhost', 6, function(err, ip, family) { + if (err) throw err; + assert.ok(net.isIPv6(ip)); + assert.strictEqual(family, 6); + + done(); + }); + + checkWrap(req); +}); */ + +process.on('exit', function() { + console.log(completed + ' tests completed'); + assert.equal(running, false); + assert.strictEqual(expected, completed); +}); diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index c3a9e03753d133..2a423f97dee7b0 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -43,75 +43,6 @@ function checkWrap(req) { assert.ok(typeof req === 'object'); } -TEST(function test_resolve4(done) { - var req = dns.resolve4('www.google.com', function(err, ips) { - if (err) throw err; - - assert.ok(ips.length > 0); - - for (var i = 0; i < ips.length; i++) { - assert.ok(isIPv4(ips[i])); - } - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_resolve6(done) { - var req = dns.resolve6('ipv6.google.com', function(err, ips) { - if (err) throw err; - - assert.ok(ips.length > 0); - - for (var i = 0; i < ips.length; i++) { - assert.ok(isIPv6(ips[i])); - } - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_reverse_ipv4(done) { - var req = dns.reverse('8.8.8.8', function(err, domains) { - if (err) throw err; - - assert.ok(domains.length > 0); - - for (var i = 0; i < domains.length; i++) { - assert.ok(domains[i]); - assert.ok(typeof domains[i] === 'string'); - } - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_reverse_ipv6(done) { - var req = dns.reverse('2001:4860:4860::8888', function(err, domains) { - if (err) throw err; - - assert.ok(domains.length > 0); - - for (var i = 0; i < domains.length; i++) { - assert.ok(domains[i]); - assert.ok(typeof domains[i] === 'string'); - } - - done(); - }); - - checkWrap(req); -}); - TEST(function test_reverse_bogus(done) { var error; @@ -290,133 +221,6 @@ TEST(function test_resolveTxt(done) { }); -TEST(function test_lookup_ipv4_explicit(done) { - var req = dns.lookup('www.google.com', 4, function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv4(ip)); - assert.strictEqual(family, 4); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_ipv4_implicit(done) { - var req = dns.lookup('www.google.com', function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv4(ip)); - assert.strictEqual(family, 4); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_ipv4_explicit_object(done) { - var req = dns.lookup('www.google.com', { - family: 4 - }, function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv4(ip)); - assert.strictEqual(family, 4); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_ipv4_hint_addrconfig(done) { - var req = dns.lookup('www.google.com', { - hints: dns.ADDRCONFIG - }, function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv4(ip)); - assert.strictEqual(family, 4); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_ipv6_explicit(done) { - var req = dns.lookup('ipv6.google.com', 6, function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv6(ip)); - assert.strictEqual(family, 6); - - done(); - }); - - checkWrap(req); -}); - - -/* This ends up just being too problematic to test -TEST(function test_lookup_ipv6_implicit(done) { - var req = dns.lookup('ipv6.google.com', function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv6(ip)); - assert.strictEqual(family, 6); - - done(); - }); - - checkWrap(req); -}); -*/ - - -TEST(function test_lookup_ipv6_explicit_object(done) { - var req = dns.lookup('ipv6.google.com', { - family: 6 - }, function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv6(ip)); - assert.strictEqual(family, 6); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_ipv6_hint(done) { - var req = dns.lookup('www.google.com', { - family: 6, - hints: dns.V4MAPPED - }, function(err, ip, family) { - if (err) { - // FreeBSD does not support V4MAPPED - if (process.platform === 'freebsd') { - assert(err instanceof Error); - assert.strictEqual(err.code, 'EAI_BADFLAGS'); - assert.strictEqual(err.hostname, 'www.google.com'); - assert.ok(/getaddrinfo EAI_BADFLAGS/.test(err.message)); - done(); - return; - } else { - throw err; - } - } - assert.ok(net.isIPv6(ip)); - assert.strictEqual(family, 6); - - done(); - }); - - checkWrap(req); -}); - - TEST(function test_lookup_failure(done) { var req = dns.lookup('does.not.exist', 4, function(err, ip, family) { assert.ok(err instanceof Error); @@ -445,45 +249,6 @@ TEST(function test_lookup_null(done) { }); -TEST(function test_lookup_ip_ipv4(done) { - var req = dns.lookup('127.0.0.1', function(err, ip, family) { - if (err) throw err; - assert.strictEqual(ip, '127.0.0.1'); - assert.strictEqual(family, 4); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_ip_ipv6(done) { - var req = dns.lookup('::1', function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv6(ip)); - assert.strictEqual(family, 6); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_localhost_ipv4(done) { - var req = dns.lookup('localhost', 4, function(err, ip, family) { - if (err) throw err; - assert.strictEqual(ip, '127.0.0.1'); - assert.strictEqual(family, 4); - - done(); - }); - - checkWrap(req); -}); - - TEST(function test_lookup_ip_all(done) { var req = dns.lookup('127.0.0.1', {all: true}, function(err, ips, family) { if (err) throw err; @@ -512,44 +277,6 @@ TEST(function test_lookup_null_all(done) { }); -TEST(function test_lookup_all_ipv4(done) { - var req = dns.lookup('www.google.com', {all: true, family: 4}, - function(err, ips) { - if (err) throw err; - assert.ok(Array.isArray(ips)); - assert.ok(ips.length > 0); - - ips.forEach(function(ip) { - assert.ok(isIPv4(ip.address)); - assert.strictEqual(ip.family, 4); - }); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookup_all_ipv6(done) { - var req = dns.lookup('www.google.com', {all: true, family: 6}, - function(err, ips) { - if (err) throw err; - assert.ok(Array.isArray(ips)); - assert.ok(ips.length > 0); - - ips.forEach(function(ip) { - assert.ok(isIPv6(ip.address)); - assert.strictEqual(ip.family, 6); - }); - - done(); - }); - - checkWrap(req); -}); - - TEST(function test_lookup_all_mixed(done) { var req = dns.lookup('www.google.com', {all: true}, function(err, ips) { if (err) throw err; @@ -572,66 +299,6 @@ TEST(function test_lookup_all_mixed(done) { }); -TEST(function test_lookupservice_ip_ipv4(done) { - var req = dns.lookupService('127.0.0.1', 80, function(err, host, service) { - if (err) throw err; - assert.equal(typeof host, 'string'); - assert(host); - - /* - * Retrieve the actual HTTP service name as setup on the host currently - * running the test by reading it from /etc/services. This is not ideal, - * as the service name lookup could use another mechanism (e.g nscd), but - * it's already better than hardcoding it. - */ - var httpServiceName = common.getServiceName(80, 'tcp'); - if (!httpServiceName) { - /* - * Couldn't find service name, reverting to the most sensible default - * for port 80. - */ - httpServiceName = 'http'; - } - - assert.strictEqual(service, httpServiceName); - - done(); - }); - - checkWrap(req); -}); - - -TEST(function test_lookupservice_ip_ipv6(done) { - var req = dns.lookupService('::1', 80, function(err, host, service) { - if (err) throw err; - assert.equal(typeof host, 'string'); - assert(host); - - /* - * Retrieve the actual HTTP service name as setup on the host currently - * running the test by reading it from /etc/services. This is not ideal, - * as the service name lookup could use another mechanism (e.g nscd), but - * it's already better than hardcoding it. - */ - var httpServiceName = common.getServiceName(80, 'tcp'); - if (!httpServiceName) { - /* - * Couldn't find service name, reverting to the most sensible default - * for port 80. - */ - httpServiceName = 'http'; - } - - assert.strictEqual(service, httpServiceName); - - done(); - }); - - checkWrap(req); -}); - - TEST(function test_lookupservice_invalid(done) { var req = dns.lookupService('1.2.3.4', 80, function(err, host, service) { assert(err instanceof Error); @@ -696,20 +363,6 @@ TEST(function test_resolve_failure(done) { }); -/* Disabled because it appears to be not working on linux. */ -/* TEST(function test_lookup_localhost_ipv6(done) { - var req = dns.lookup('localhost', 6, function(err, ip, family) { - if (err) throw err; - assert.ok(net.isIPv6(ip)); - assert.strictEqual(family, 6); - - done(); - }); - - checkWrap(req); -}); */ - - var getaddrinfoCallbackCalled = false; console.log('looking up nodejs.org...');