Browse Source

In tests, wait for 'listening' before connecting

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
0301adf9b4
  1. 22
      test/pummel/test-keep-alive.js
  2. 32
      test/simple/test-http-cat.js

22
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();
});
});
});

32
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 () {

Loading…
Cancel
Save