Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1bc44e7

Browse filesBrowse files
mscdexMyles Borins
authored andcommitted
test: try other ipv6 localhost alternatives
PR-URL: #4325 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1ebb0c0 commit 1bc44e7
Copy full SHA for 1bc44e7

File tree

Expand file treeCollapse file tree

2 files changed

+68
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+68
-41
lines changed
Open diff view settings
Collapse file

‎test/common.js‎

Copy file name to clipboardExpand all lines: test/common.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ var opensslCli = null;
7979
var inFreeBSDJail = null;
8080
var localhostIPv4 = null;
8181

82+
exports.localIPv6Hosts = [
83+
// Debian/Ubuntu
84+
'ip6-localhost',
85+
'ip6-loopback',
86+
87+
// SUSE
88+
'ipv6-localhost',
89+
'ipv6-loopback',
90+
91+
// Typically universal
92+
'localhost',
93+
];
94+
8295
Object.defineProperty(exports, 'inFreeBSDJail', {
8396
get: function() {
8497
if (inFreeBSDJail !== null) return inFreeBSDJail;
Collapse file
+55-41Lines changed: 55 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
4-
var net = require('net');
5-
var dns = require('dns');
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
const dns = require('dns');
66

77
if (!common.hasIPv6) {
88
console.log('1..0 # Skipped: no IPv6 support');
@@ -12,46 +12,60 @@ if (!common.hasIPv6) {
1212
var serverGotEnd = false;
1313
var clientGotEnd = false;
1414

15-
dns.lookup('localhost', 6, function(err) {
16-
if (err) {
17-
console.error('Looks like IPv6 is not really supported');
18-
console.error(err);
19-
return;
20-
}
15+
const hosts = common.localIPv6Hosts;
16+
var hostIdx = 0;
17+
var host = hosts[hostIdx];
18+
var localhostTries = 10;
2119

22-
var server = net.createServer({allowHalfOpen: true}, function(socket) {
23-
socket.resume();
24-
socket.on('end', function() {
25-
serverGotEnd = true;
26-
});
27-
socket.end();
20+
const server = net.createServer({allowHalfOpen: true}, function(socket) {
21+
socket.resume();
22+
socket.on('end', function() {
23+
serverGotEnd = true;
2824
});
25+
socket.end();
26+
});
2927

30-
server.listen(common.PORT, '::1', function() {
31-
var client = net.connect({
32-
host: 'localhost',
33-
port: common.PORT,
34-
family: 6,
35-
allowHalfOpen: true
36-
}, function() {
37-
console.error('client connect cb');
38-
client.resume();
39-
client.on('end', function() {
40-
clientGotEnd = true;
41-
setTimeout(function() {
42-
assert(client.writable);
43-
client.end();
44-
}, 10);
45-
});
46-
client.on('close', function() {
47-
server.close();
48-
});
28+
server.listen(common.PORT, '::1', tryConnect);
29+
30+
function tryConnect() {
31+
const client = net.connect({
32+
host: host,
33+
port: common.PORT,
34+
family: 6,
35+
allowHalfOpen: true
36+
}, function() {
37+
console.error('client connect cb');
38+
client.resume();
39+
client.on('end', function() {
40+
clientGotEnd = true;
41+
setTimeout(function() {
42+
assert(client.writable);
43+
client.end();
44+
}, 10);
45+
});
46+
client.on('close', function() {
47+
server.close();
4948
});
49+
}).on('error', function(err) {
50+
if (err.syscall === 'getaddrinfo' && err.code === 'ENOTFOUND') {
51+
if (host !== 'localhost' || --localhostTries === 0)
52+
host = hosts[++hostIdx];
53+
if (host)
54+
tryConnect();
55+
else {
56+
console.log('1..0 # Skipped: no IPv6 localhost support');
57+
process.removeListener('exit', onExit);
58+
server.close();
59+
}
60+
return;
61+
}
62+
throw err;
5063
});
64+
}
5165

52-
process.on('exit', function() {
53-
console.error('exit', serverGotEnd, clientGotEnd);
54-
assert(serverGotEnd);
55-
assert(clientGotEnd);
56-
});
57-
});
66+
process.on('exit', onExit);
67+
function onExit() {
68+
console.error('exit', serverGotEnd, clientGotEnd);
69+
assert(serverGotEnd);
70+
assert(clientGotEnd);
71+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.