From eda21cccb4caf0ba8be325b79c6c37ecaf1845c3 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 19 Jun 2010 23:13:28 -0700 Subject: [PATCH] Fix race condition in test-http-exceptions.js --- test/simple/test-http-exceptions.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/simple/test-http-exceptions.js b/test/simple/test-http-exceptions.js index b1ffc6dfe8..042eedfbf3 100644 --- a/test/simple/test-http-exceptions.js +++ b/test/simple/test-http-exceptions.js @@ -12,7 +12,6 @@ server = http.createServer(function (req, res) { res.write(server_response); res.end(); }); -server.listen(PORT); function check_reqs() { var done_reqs = 0; @@ -47,9 +46,18 @@ function add_client(num) { return req; } -for (req_num = 0; req_num < 4 ; req_num += 1) { - client_requests.push(add_client(req_num)); -} +server.listen(PORT, function () { + for (req_num = 0; req_num < 4 ; req_num += 1) { + client_requests.push(add_client(req_num)); + } + + timer = setTimeout(function () { + process.removeListener("uncaughtException", exception_handler); + server.close(); + assert.strictEqual(4, exception_count); + process.exit(0); + }, 300); +}); function exception_handler(err) { sys.puts("Caught an exception: " + err); @@ -58,11 +66,5 @@ function exception_handler(err) { } exception_count += 1; } -process.addListener("uncaughtException", exception_handler); -timer = setTimeout(function () { - process.removeListener("uncaughtException", exception_handler); - server.close(); - assert.strictEqual(4, exception_count); - process.exit(0); -}, 300); +process.addListener("uncaughtException", exception_handler);