Skip to content

Commit

Permalink
test: dynamic port in cluster eaddrinuse
Browse files Browse the repository at this point in the history
Removed common.PORT from test-cluster-eaddrinuse to eliminate the
possibility that a dynamic port used in another test will collide
with common.PORT.

PR-URL: #12547
Ref: #12376
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Sebastian Plesciuc authored and evanlucas committed May 1, 2017
1 parent 6ec0ca0 commit 7b6e368
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions test/parallel/test-cluster-eaddrinuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const fork = require('child_process').fork;
const net = require('net');

const id = '' + process.argv[2];
const port = '' + process.argv[3];

if (id === 'undefined') {
const server = net.createServer(common.mustNotCall());
server.listen(common.PORT, function() {
const worker = fork(__filename, ['worker']);
server.listen(0, function() {
const worker = fork(__filename, ['worker', server.address().port]);
worker.on('message', function(msg) {
if (msg !== 'stop-listening') return;
server.close(function() {
Expand All @@ -23,14 +24,14 @@ if (id === 'undefined') {
});
} else if (id === 'worker') {
let server = net.createServer(common.mustNotCall());
server.listen(common.PORT, common.mustNotCall());
server.listen(port, common.mustNotCall());
server.on('error', common.mustCall(function(e) {
assert(e.code, 'EADDRINUSE');
process.send('stop-listening');
process.once('message', function(msg) {
if (msg !== 'stopped-listening') return;
server = net.createServer(common.mustNotCall());
server.listen(common.PORT, common.mustCall(function() {
server.listen(port, common.mustCall(function() {
server.close();
}));
});
Expand Down

0 comments on commit 7b6e368

Please sign in to comment.