Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: harden test-child-process-fork-regr-gh-2847 #3459

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion test/parallel/test-child-process-fork-regr-gh-2847.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const cluster = require('cluster');
const net = require('net');
const util = require('util');

var connectcount = 0;
var sendcount = 0;

if (!cluster.isMaster) {
// Exit on first received handle to leave the queue non-empty in master
process.on('message', function() {
Expand All @@ -25,6 +28,21 @@ var server = net.createServer(function(s) {
function send(callback) {
var s = net.connect(common.PORT, function() {
worker.send({}, s, callback);
connectcount++;
});

// Errors can happen if the connections
// are still happening while the server has been closed.
// This can happen depending on how the messages are
// bundled into packets. If they all make it into the first
// one then no errors will occur, otherwise the server
// may have been closed by the time the later ones make
// it to the server side.
// We ignore any errors that occur after some connections
// get through
s.on('error', function(err) {
if (connectcount < 3)
console.log(err);
});
}

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

// Queue up several handles, to make `process.disconnect()` wait
for (var i = 0; i < 100; i++)
send();
send(function(err) {
if (err && sendcount < 3)
console.log(err);
sendcount++;
});
});