Skip to content

Commit

Permalink
test: dynamic port in parallel regress tests
Browse files Browse the repository at this point in the history
Removed common.PORT from test-regress-GH-5051 and
test-regress-GH-5727 in order to eliminate the possibility
of port collision.

Refs: #12376
PR-URL: #12639
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
  • Loading branch information
Sebastian Plesciuc authored and gibfahn committed Jun 20, 2017
1 parent 58750d4 commit b979502
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions test/parallel/test-regress-GH-5051.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const agent = require('http').globalAgent;

Expand All @@ -12,20 +12,22 @@ agent.maxSockets = 0;

// localAddress is used when naming requests / sockets
// while using the Legacy API
agent.addRequest(req, 'localhost', common.PORT, '127.0.0.1');
// port 8080 is hardcoded since this does not create a network connection
agent.addRequest(req, 'localhost', 8080, '127.0.0.1');
assert.strictEqual(Object.keys(agent.requests).length, 1);
assert.strictEqual(
Object.keys(agent.requests)[0],
'localhost:' + common.PORT + ':127.0.0.1');
'localhost:8080:127.0.0.1');

// path is *not* used when naming requests / sockets
// port 8080 is hardcoded since this does not create a network connection
agent.addRequest(req, {
host: 'localhost',
port: common.PORT,
port: 8080,
localAddress: '127.0.0.1',
path: '/foo'
});
assert.strictEqual(Object.keys(agent.requests).length, 1);
assert.strictEqual(
Object.keys(agent.requests)[0],
'localhost:' + common.PORT + ':127.0.0.1');
'localhost:8080:127.0.0.1');
4 changes: 2 additions & 2 deletions test/parallel/test-regress-GH-5727.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const net = require('net');
const invalidPort = -1 >>> 0;
const errorMessage = /"port" argument must be >= 0 and < 65536/;

net.Server().listen(common.PORT, function() {
net.Server().listen(0, function() {
const address = this.address();
const key = `${address.family.slice(-1)}:${address.address}:${common.PORT}`;
const key = `${address.family.slice(-1)}:${address.address}:0`;

assert.strictEqual(this._connectionKey, key);
this.close();
Expand Down

0 comments on commit b979502

Please sign in to comment.