Skip to content

Commit 042e858

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
test: make test-child-process-fork-net more robust
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: #7033 Reviewed-By: Brian White <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 9d13337 commit 042e858

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

test/parallel/test-child-process-fork-net.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
const assert = require('assert');
3-
const common = require('../common');
3+
require('../common');
44
const fork = require('child_process').fork;
55
const net = require('net');
66

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

9696
// handle client messages
9797
var messageHandlers = function(msg) {
@@ -100,7 +100,7 @@ if (process.argv[2] === 'child') {
100100
// make connections
101101
var socket;
102102
for (var i = 0; i < 4; i++) {
103-
socket = net.connect(common.PORT, function() {
103+
socket = net.connect(server.address().port, function() {
104104
console.log('CLIENT: connected');
105105
});
106106
socket.on('close', function() {
@@ -143,9 +143,9 @@ if (process.argv[2] === 'child') {
143143
//
144144
// An isolated test for this would be lovely, but for now, this
145145
// will have to do.
146-
server.listen(common.PORT + 1, function() {
146+
server.listen(0, function() {
147147
console.error('testSocket, listening');
148-
var connect = net.connect(common.PORT + 1);
148+
var connect = net.connect(server.address().port);
149149
var store = '';
150150
connect.on('data', function(chunk) {
151151
store += chunk;

0 commit comments

Comments
 (0)