test: fix race condition in test-http-client-onerror
authorDevin Nakamura <devinn@ca.ibm.com>
Fri, 18 Dec 2015 15:50:11 +0000 (10:50 -0500)
committerMyles Borins <mborins@us.ibm.com>
Tue, 19 Jan 2016 19:52:27 +0000 (11:52 -0800)
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 <info@bnoordhuis.nl>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Reviewed-By: James M Snell <jasnell@gmail.com>
test/gc/test-http-client-onerror.js

index 98d046e..7e50683 100644 (file)
@@ -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 ++;