diff --git a/test/common.js b/test/common.js index 43f4362b45cbfe..1074238c69e8e1 100644 --- a/test/common.js +++ b/test/common.js @@ -80,19 +80,6 @@ var opensslCli = null; var inFreeBSDJail = null; var localhostIPv4 = null; -exports.localIPv6Hosts = [ - // Debian/Ubuntu - 'ip6-localhost', - 'ip6-loopback', - - // SUSE - 'ipv6-localhost', - 'ipv6-loopback', - - // Typically universal - 'localhost', -]; - Object.defineProperty(exports, 'inFreeBSDJail', { get: function() { if (inFreeBSDJail !== null) return inFreeBSDJail; diff --git a/test/parallel/test-net-connect-options-ipv6.js b/test/parallel/test-net-connect-options-ipv6.js index 8b11612a1286f2..f644b60a88e9bc 100644 --- a/test/parallel/test-net-connect-options-ipv6.js +++ b/test/parallel/test-net-connect-options-ipv6.js @@ -1,56 +1,58 @@ 'use strict'; -const common = require('../common'); -const assert = require('assert'); -const net = require('net'); + +var common = require('../common'); +var assert = require('assert'); +var net = require('net'); +var dns = require('dns'); if (!common.hasIPv6) { console.log('1..0 # Skipped: no IPv6 support'); return; } -const hosts = common.localIPv6Hosts; -var hostIdx = 0; -var host = hosts[hostIdx]; -var localhostTries = 10; - -const server = net.createServer({allowHalfOpen: true}, function(socket) { - socket.resume(); - socket.on('end', common.mustCall(function() {})); - socket.end(); -}); +var serverGotEnd = false; +var clientGotEnd = false; -server.listen(common.PORT, '::1', tryConnect); +dns.lookup('localhost', 6, function(err) { + if (err) { + console.error('Looks like IPv6 is not really supported'); + console.error(err); + return; + } -function tryConnect() { - const client = net.connect({ - host: host, - port: common.PORT, - family: 6, - allowHalfOpen: true - }, function() { - console.error('client connect cb'); - client.resume(); - client.on('end', common.mustCall(function() { - setTimeout(function() { - assert(client.writable); - client.end(); - }, 10); - })); - client.on('close', function() { - server.close(); + var server = net.createServer({allowHalfOpen: true}, function(socket) { + socket.resume(); + socket.on('end', function() { + serverGotEnd = true; }); - }).on('error', function(err) { - if (err.syscall === 'getaddrinfo' && err.code === 'ENOTFOUND') { - if (host !== 'localhost' || --localhostTries === 0) - host = hosts[++hostIdx]; - if (host) - tryConnect(); - else { - console.log('1..0 # Skipped: no IPv6 localhost support'); + socket.end(); + }); + + server.listen(common.PORT, '::1', function() { + var client = net.connect({ + host: 'localhost', + port: common.PORT, + family: 6, + allowHalfOpen: true + }, function() { + console.error('client connect cb'); + client.resume(); + client.on('end', function() { + clientGotEnd = true; + setTimeout(function() { + assert(client.writable); + client.end(); + }, 10); + }); + client.on('close', function() { server.close(); - } - return; - } - throw err; + }); + }); }); -} + + process.on('exit', function() { + console.error('exit', serverGotEnd, clientGotEnd); + assert(serverGotEnd); + assert(clientGotEnd); + }); +});