Skip to content

Commit 7c35fbc

Browse files
mhdawsonrvagg
authored andcommitted
test: harden test-child-process-fork-regr-gh-2847
test-child-process-fork-regr-gh-2847 could fail depending on timing and how messages were packed into tcp packets. If all of the requests fit into one packet then the test worked otherwise, otherwise errors could occur. This PR modifies the test to be tolerant while still validating that some of the connection can be made succesfully Reviewed-By: James M Snell <[email protected]> PR-URL: #3459
1 parent ad2b272 commit 7c35fbc

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/parallel/test-child-process-fork-regr-gh-2847.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const cluster = require('cluster');
77
const net = require('net');
88
const util = require('util');
99

10+
var connectcount = 0;
11+
var sendcount = 0;
12+
1013
if (!cluster.isMaster) {
1114
// Exit on first received handle to leave the queue non-empty in master
1215
process.on('message', function() {
@@ -25,6 +28,21 @@ var server = net.createServer(function(s) {
2528
function send(callback) {
2629
var s = net.connect(common.PORT, function() {
2730
worker.send({}, s, callback);
31+
connectcount++;
32+
});
33+
34+
// Errors can happen if the connections
35+
// are still happening while the server has been closed.
36+
// This can happen depending on how the messages are
37+
// bundled into packets. If they all make it into the first
38+
// one then no errors will occur, otherwise the server
39+
// may have been closed by the time the later ones make
40+
// it to the server side.
41+
// We ignore any errors that occur after some connections
42+
// get through
43+
s.on('error', function(err) {
44+
if (connectcount < 3)
45+
console.log(err);
2846
});
2947
}
3048

@@ -36,5 +54,9 @@ var server = net.createServer(function(s) {
3654

3755
// Queue up several handles, to make `process.disconnect()` wait
3856
for (var i = 0; i < 100; i++)
39-
send();
57+
send(function(err) {
58+
if (err && sendcount < 3)
59+
console.log(err);
60+
sendcount++;
61+
});
4062
});

0 commit comments

Comments
 (0)