node/test/parallel/test-net-local-address-port.js
Rod Vagg f600111d82 test: cache lazy properties, fix style nits
inFreeBSDJail involves an execSync() and is used by localhost_ipv4 so
will be unnecessarily expensive, so cache both values and reuse
rather than re-evaluate each time.

Renamed localhost_ipv4 to localhostIPv4 for style consistency.

PR-URL: https://github.com/iojs/io.js/pull/1196
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-03-19 16:27:45 +11:00

27 lines
637 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.localhostIPv4, socket.localAddress);
assert.equal(socket.localPort, common.PORT);
socket.on('end', function() {
server.close();
});
socket.resume();
});
server.listen(common.PORT, common.localhostIPv4, function() {
var client = net.createConnection(common.PORT, common.localhostIPv4);
client.on('connect', function() {
client.end();
});
});
process.on('exit', function() {
assert.equal(1, conns);
});