test: fix race condition in test-http-client-onerror

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>
This commit is contained in:
Devin Nakamura 2015-12-18 10:50:11 -05:00 committed by James M Snell
parent a030c5cf49
commit 2413a4e99d

View 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 ++;