From 304eda46a4be3887fc589087e086b2e0f500fd1a Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 20 Oct 2015 18:35:34 -0400 Subject: [PATCH] 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 PR-URL: https://github.com/nodejs/node/pull/3459 --- .../test-child-process-fork-regr-gh-2847.js | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-child-process-fork-regr-gh-2847.js b/test/parallel/test-child-process-fork-regr-gh-2847.js index 07ef6415a3c3e1..27b4d72d2fc612 100644 --- a/test/parallel/test-child-process-fork-regr-gh-2847.js +++ b/test/parallel/test-child-process-fork-regr-gh-2847.js @@ -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() { @@ -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); }); } @@ -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++; + }); });