Conversation
|
What do you think about this? diff --git a/test/WebSocket.test.js b/test/WebSocket.test.js
index 178dbfd..6e8318e 100644
--- a/test/WebSocket.test.js
+++ b/test/WebSocket.test.js
@@ -7,7 +7,9 @@ const assert = require('assert');
const crypto = require('crypto');
const https = require('https');
const http = require('http');
+const dns = require('dns');
const net = require('net');
+const os = require('os');
const fs = require('fs');
const constants = require('../lib/Constants');
@@ -95,20 +97,35 @@ describe('WebSocket', function () {
});
it('accepts the family option', function (done) {
- const wss = new WebSocket.Server({ host: '::1', port: 0 }, () => {
- const port = wss._server.address().port;
- const ws = new WebSocket(`ws://localhost:${port}`, { family: 6 });
+ const re = process.platform === 'win32' ? /Loopback Pseudo-Interface/ : /lo/;
+ const ifaces = os.networkInterfaces();
+ const hasIPv6 = Object.keys(ifaces).some((name) => {
+ return re.test(name) && ifaces[name].some((info) => info.family === 'IPv6');
});
- wss.on('error', (err) => {
- // Skip this test on machines where IPv6 is not supported.
- if (err.code === 'EADDRNOTAVAIL') err = undefined;
- wss.close(() => done(err));
- });
+ // Skip this test on machines where IPv6 is not supported.
+ if (!hasIPv6) return done();
- wss.on('connection', (ws, req) => {
- assert.strictEqual(req.connection.remoteAddress, '::1');
- wss.close(done);
+ dns.lookup('localhost', { family: 6, all: true }, (err, addresses) => {
+ // Skip this test if localhost does not resolve to ::1.
+ if (err) {
+ if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN') {
+ err = undefined;
+ }
+ return done(err);
+ }
+
+ if (!addresses.some((val) => val.address === '::1')) return done();
+
+ const wss = new WebSocket.Server({ host: '::1', port: 0 }, () => {
+ const port = wss._server.address().port;
+ const ws = new WebSocket(`ws://localhost:${port}`, { family: 6 });
+ });
+
+ wss.on('connection', (ws, req) => {
+ assert.strictEqual(req.connection.remoteAddress, '::1');
+ wss.close(done);
+ });
});
});
});It's a little better as it doesn't run the test multiple times if both |
|
We can use |
|
I would replace And with this change the test will be skipped (or succeed without testing anything). My /etc/hosts is standard, there is nothing strange, just a regular linux machine. Btw the test is probably skipped on the CI and it's invisible ;-) |
|
For example Red Hat Enterprise Linux 5 |
|
@dcharbonnier yes same is on fedora but if you do or try to resolve with |
but ok, let's change it with your proposal will see |
|
You can update this PR if you want. |
|
easier to push your branch :-) |
e34f383 to
e90159c
Compare
|
Thank you. |
|
Thank you, so now we know this test never pass in the CI ;-) |
|
It passes on AppVeyor and it used to pass on Travis CI when it was possible to bind the server on |
Seams a bit complicated but it's more consistent than simply skipping silently a test.
If the test is skipped it will be mentioned on the result (maybe we should raise an error during ci if a test is skipped) and the test will pass on more machine trying a list of potential alias for the loop-back.
with
const hostsCandidates = ['localhost'];with
const hostsCandidates = ['localhost', 'ip6-loopback'];with
const hostsCandidates = ['localhost', 'ip6-allnodes'];