From 761af37d0ea075e0c29ca95c8117a628e310c25f Mon Sep 17 00:00:00 2001 From: Devin Nakamura Date: Fri, 18 Dec 2015 10:50:11 -0500 Subject: [PATCH] test: fix race condition in test-http-client-onerror MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Occasionally test-http-client-onerror will fail with a refused connection. This patch fixes the possibility that connections will be attempted before server is listening. PR-URL: https://github.com/nodejs/node/pull/4346 Reviewed-By: Ben Noordhuis Reviewed-By: Brian White Reviewed-By: Johan Bergström Reviewed-By: James M Snell --- test/gc/test-http-client-onerror.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/gc/test-http-client-onerror.js b/test/gc/test-http-client-onerror.js index 98d046e180f11b..7e50683c6633e5 100644 --- a/test/gc/test-http-client-onerror.js +++ b/test/gc/test-http-client-onerror.js @@ -22,7 +22,7 @@ console.log('We should do ' + todo + ' requests'); var http = require('http'); var server = http.createServer(serverHandler); -server.listen(PORT, getall); +server.listen(PORT, runTest); function getall() { if (count >= todo) @@ -51,8 +51,10 @@ function getall() { setImmediate(getall); } -for (var i = 0; i < 10; i++) - getall(); +function runTest() { + for (var i = 0; i < 10; i++) + getall(); +} function afterGC() { countGC ++;