Browse Source

Fix race condition in test-http-exceptions.js

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
eda21cccb4
  1. 18
      test/simple/test-http-exceptions.js

18
test/simple/test-http-exceptions.js

@ -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;
@ -47,10 +46,19 @@ function add_client(num) {
return req; return req;
} }
server.listen(PORT, function () {
for (req_num = 0; req_num < 4 ; req_num += 1) { for (req_num = 0; req_num < 4 ; req_num += 1) {
client_requests.push(add_client(req_num)); 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);
if (err.name === "AssertionError") { if (err.name === "AssertionError") {
@ -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);

Loading…
Cancel
Save