0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-dgram-error-message-address.js
Ben Noordhuis 62512bb29c test: accept EPROTONOSUPPORT ipv6 error
The IPv6 test in parallel/test-dgram-error-message-address may fail
when the host system has disabled IPv6, as is the case on our FreeBSD
machines.  The test already accepted EAFNOSUPPORT as of commit 5ba307a,
now make it accept EPROTONOSUPPORT as well.

I'm not exactly thrilled by the profusion of error codes but they are
all legitimate.

PR-URL: https://github.com/iojs/io.js/pull/733
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2015-02-06 00:49:00 +01:00

37 lines
1.1 KiB
JavaScript

var common = require('../common');
var assert = require('assert');
var dgram = require('dgram');
// IPv4 Test
var socket_ipv4 = dgram.createSocket('udp4');
socket_ipv4.on('listening', assert.fail);
socket_ipv4.on('error', common.mustCall(function(e) {
assert.equal(e.message, 'bind EADDRNOTAVAIL 1.1.1.1:' + common.PORT);
assert.equal(e.address, '1.1.1.1');
assert.equal(e.port, common.PORT);
assert.equal(e.code, 'EADDRNOTAVAIL');
socket_ipv4.close();
}));
socket_ipv4.bind(common.PORT, '1.1.1.1');
// IPv6 Test
var socket_ipv6 = dgram.createSocket('udp6');
var family_ipv6 = 'IPv6';
socket_ipv6.on('listening', assert.fail);
socket_ipv6.on('error', common.mustCall(function(e) {
// EAFNOSUPPORT or EPROTONOSUPPORT means IPv6 is disabled on this system.
var allowed = ['EADDRNOTAVAIL', 'EAFNOSUPPORT', 'EPROTONOSUPPORT'];
assert.notEqual(allowed.indexOf(e.code), -1);
assert.equal(e.message, 'bind ' + e.code + ' 111::1:' + common.PORT);
assert.equal(e.address, '111::1');
assert.equal(e.port, common.PORT);
socket_ipv6.close();
}));
socket_ipv6.bind(common.PORT, '111::1');