node/test/parallel/test-net-local-address-port.js
Johan Bergström c15e81afdd test: Introduce knowledge of FreeBSD jails
FreeBSD jails act differently than your average vm or similar
application container. All routing passes through one ip address,
which makes things like localhost or 0.0.0.0 resolve differently.

Introduce a helper that allows us to verify if we're in a jail
and another one for returning an ip address for localhost.

Also, skip one test instead of trading additional complexity
in common.js for one specific user scenario.

PR-URL: https://github.com/iojs/io.js/pull/1167
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-03-19 09:11:50 +11:00

27 lines
640 B
JavaScript

var common = require('../common');
var assert = require('assert');
var net = require('net');
var conns = 0, conns_closed = 0;
var server = net.createServer(function(socket) {
conns++;
assert.equal(common.localhost_ipv4, socket.localAddress);
assert.equal(socket.localPort, common.PORT);
socket.on('end', function() {
server.close();
});
socket.resume();
});
server.listen(common.PORT, common.localhost_ipv4, function() {
var client = net.createConnection(common.PORT, common.localhost_ipv4);
client.on('connect', function() {
client.end();
});
});
process.on('exit', function() {
assert.equal(1, conns);
});