From 0301adf9b44a966ba0d2503ab79a6583e7f6436b Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 5 Apr 2010 11:32:18 -0700 Subject: [PATCH] In tests, wait for 'listening' before connecting --- test/pummel/test-keep-alive.js | 22 ++++++++++++---------- test/simple/test-http-cat.js | 32 +++++++++++++++++--------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/test/pummel/test-keep-alive.js b/test/pummel/test-keep-alive.js index d52f06659b..5b71d4b00a 100644 --- a/test/pummel/test-keep-alive.js +++ b/test/pummel/test-keep-alive.js @@ -42,16 +42,18 @@ function runAb(opts, callback) { }); } -runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) { - keepAliveReqSec = reqSec; - assert.equal(true, keepAliveRequests > 0); - puts("keep-alive: " + keepAliveReqSec + " req/sec"); - - runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) { - normalReqSec = reqSec; - assert.equal(0, keepAliveRequests); - puts("normal: " + normalReqSec + " req/sec"); - server.close(); +server.addListener('listening', function () { + runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) { + keepAliveReqSec = reqSec; + assert.equal(true, keepAliveRequests > 0); + puts("keep-alive: " + keepAliveReqSec + " req/sec"); + + runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) { + normalReqSec = reqSec; + assert.equal(0, keepAliveRequests); + puts("normal: " + normalReqSec + " req/sec"); + server.close(); + }); }); }); diff --git a/test/simple/test-http-cat.js b/test/simple/test-http-cat.js index e81a5c502f..f333b5e7d9 100644 --- a/test/simple/test-http-cat.js +++ b/test/simple/test-http-cat.js @@ -16,22 +16,24 @@ server.listen(PORT); var got_good_server_content = false; var bad_server_got_error = false; -http.cat("http://localhost:"+PORT+"/", "utf8", function (err, content) { - if (err) { - throw err; - } else { - puts("got response"); - got_good_server_content = true; - assert.equal(body, content); - server.close(); - } -}); +server.addListener('listening', function () { + http.cat("http://localhost:"+PORT+"/", "utf8", function (err, content) { + if (err) { + throw err; + } else { + puts("got response"); + got_good_server_content = true; + assert.equal(body, content); + server.close(); + } + }); -http.cat("http://localhost:12312/", "utf8", function (err, content) { - if (err) { - puts("got error (this should happen)"); - bad_server_got_error = true; - } + http.cat("http://localhost:12312/", "utf8", function (err, content) { + if (err) { + puts("got error (this should happen)"); + bad_server_got_error = true; + } + }); }); process.addListener("exit", function () {