Skip to content

Commit

Permalink
[test] Skip family option test if IPv6 is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Nov 2, 2017
1 parent e5772a3 commit 72751d3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/WebSocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ describe('WebSocket', function () {
const ws = new WebSocket(`ws://localhost:${port}`, { family: 6 });
});

wss.on('error', (err) => {
// Skip this test on machines where IPv6 is not supported.
if (err.code === 'EADDRNOTAVAIL') err = undefined;
wss.close(() => done(err));
});

wss.on('connection', (ws, req) => {
assert.strictEqual(req.connection.remoteAddress, '::1');
wss.close(done);
Expand Down

5 comments on commit 72751d3

@dcharbonnier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on my machine, elementary os (based on ubuntu) there is no ipv6 entry for "localhost"
::1 ip6-localhost ip6-loopback

@lpinca
Copy link
Member Author

@lpinca lpinca commented on 72751d3 Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the error emitted and the test skipped in that case?

@dcharbonnier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no and the tests never end

  1) WebSocket
       options
         accepts the family option:
     Uncaught Error: getaddrinfo ENOTFOUND localhost localhost:38935
      at errnoException (dns.js:55:10)
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:26)

@lpinca
Copy link
Member Author

@lpinca lpinca commented on 72751d3 Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we should refactor it then, not sure why the error isn't emitted though.

@lpinca
Copy link
Member Author

@lpinca lpinca commented on 72751d3 Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the 'error' listener is on the server... I'm tired. We need another on the client which does the same thing. Something like this:

ws.on('error', (err) => {
  // Skip this test if there is no IPv6 entry for localhost.
  if (err.code === 'ENOTFOUND') err = undefined:
  wss.close(() => done(err))
});

Please sign in to comment.