node/test/parallel/test-regress-GH-5727.js
Sebastian Plesciuc e927809eec
test: dynamic port in parallel regress tests
Removed common.PORT from test-regress-GH-5051 and
test-regress-GH-5727 in order to eliminate the possibility
of port collision.

Refs: https://github.com/nodejs/node/issues/12376
PR-URL: https://github.com/nodejs/node/pull/12639
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
2017-04-27 17:09:56 +02:00

31 lines
882 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const invalidPort = -1 >>> 0;
const errorMessage = /"port" argument must be >= 0 and < 65536/;
net.Server().listen(0, function() {
const address = this.address();
const key = `${address.family.slice(-1)}:${address.address}:0`;
assert.strictEqual(this._connectionKey, key);
this.close();
});
// The first argument is a configuration object
assert.throws(() => {
net.Server().listen({ port: invalidPort }, common.mustNotCall());
}, errorMessage);
// The first argument is the port, no IP given.
assert.throws(() => {
net.Server().listen(invalidPort, common.mustNotCall());
}, errorMessage);
// The first argument is the port, the second an IP.
assert.throws(() => {
net.Server().listen(invalidPort, '0.0.0.0', common.mustNotCall());
}, errorMessage);