Skip to content

Commit

Permalink
test: make test-child-process-fork-net more robust
Browse files Browse the repository at this point in the history
test-child-process-fork-net will sometimes fail in CI with EADDRINUSE
because an earlier test failed to free common.PORT. Have the operating
system provide an available port instead.

PR-URL: nodejs#7033
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Trott committed Jun 1, 2016
1 parent 2f417c3 commit e4b78c6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/parallel/test-child-process-fork-net.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const assert = require('assert');
const common = require('../common');
require('../common');
const fork = require('child_process').fork;
const net = require('net');

Expand Down Expand Up @@ -91,7 +91,7 @@ if (process.argv[2] === 'child') {
console.log('PARENT: server listening');
child.send({what: 'server'}, server);
});
server.listen(common.PORT);
server.listen(0);

// handle client messages
var messageHandlers = function(msg) {
Expand All @@ -100,7 +100,7 @@ if (process.argv[2] === 'child') {
// make connections
var socket;
for (var i = 0; i < 4; i++) {
socket = net.connect(common.PORT, function() {
socket = net.connect(server.address().port, function() {
console.log('CLIENT: connected');
});
socket.on('close', function() {
Expand Down Expand Up @@ -143,9 +143,9 @@ if (process.argv[2] === 'child') {
//
// An isolated test for this would be lovely, but for now, this
// will have to do.
server.listen(common.PORT + 1, function() {
server.listen(0, function() {
console.error('testSocket, listening');
var connect = net.connect(common.PORT + 1);
var connect = net.connect(server.address().port);
var store = '';
connect.on('data', function(chunk) {
store += chunk;
Expand Down

0 comments on commit e4b78c6

Please sign in to comment.