Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Fix race condition in test-http-exceptions.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jun 20, 2010
1 parent b93faf9 commit eda21cc
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions test/simple/test-http-exceptions.js
Expand Up @@ -12,7 +12,6 @@ server = http.createServer(function (req, res) {
res.write(server_response); res.write(server_response);
res.end(); res.end();
}); });
server.listen(PORT);


function check_reqs() { function check_reqs() {
var done_reqs = 0; var done_reqs = 0;
Expand Down Expand Up @@ -47,9 +46,18 @@ function add_client(num) {
return req; return req;
} }


for (req_num = 0; req_num < 4 ; req_num += 1) { server.listen(PORT, function () {
client_requests.push(add_client(req_num)); 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) { function exception_handler(err) {
sys.puts("Caught an exception: " + err); sys.puts("Caught an exception: " + err);
Expand All @@ -58,11 +66,5 @@ function exception_handler(err) {
} }
exception_count += 1; exception_count += 1;
} }
process.addListener("uncaughtException", exception_handler);


timer = setTimeout(function () { process.addListener("uncaughtException", exception_handler);
process.removeListener("uncaughtException", exception_handler);
server.close();
assert.strictEqual(4, exception_count);
process.exit(0);
}, 300);

0 comments on commit eda21cc

Please sign in to comment.