Browse Source

Fix tests

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
a8c2bb41af
  1. 6
      test/pummel/test-keep-alive.js
  2. 65
      test/pummel/test-net-pingpong-delay.js
  3. 61
      test/pummel/test-net-pingpong.js
  4. 59
      test/pummel/test-net-throttle.js
  5. 5
      test/simple/test-http-full-response.js

6
test/pummel/test-keep-alive.js

@ -22,8 +22,10 @@ function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/"; var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
exec(command, function (err, stdout, stderr) { exec(command, function (err, stdout, stderr) {
if (err) { if (err) {
console.log("ab not installed? skipping test.\n" + stderr); if (stderr.indexOf("ab") >= 0) {
process.exit(); console.log("ab not installed? skipping test.\n" + stderr);
process.reallyExit(0);
}
return; return;
} }
if (err) throw err; if (err) throw err;

65
test/pummel/test-net-pingpong-delay.js

@ -43,45 +43,46 @@ function pingPongTest (port, host, on_complete) {
socket.server.close(); socket.server.close();
}); });
}); });
server.listen(port, host);
var client = net.createConnection(port, host); server.listen(port, host, function () {
var client = net.createConnection(port, host);
client.setEncoding("utf8"); client.setEncoding("utf8");
client.addListener("connect", function () { client.addListener("connect", function () {
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
client.write("PING"); client.write("PING");
}); });
client.addListener("data", function (data) {
console.log(data);
assert.equal("PONG", data);
assert.equal("open", client.readyState);
setTimeout(function () { client.addListener("data", function (data) {
console.log(data);
assert.equal("PONG", data);
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
if (count++ < N) {
client.write("PING");
} else {
console.log("closing client");
client.end();
client_ended = true;
}
}, DELAY);
});
client.addListener("timeout", function () { setTimeout(function () {
common.debug("client-side timeout!!"); assert.equal("open", client.readyState);
assert.equal(false, true); if (count++ < N) {
}); client.write("PING");
} else {
console.log("closing client");
client.end();
client_ended = true;
}
}, DELAY);
});
client.addListener("close", function () { client.addListener("timeout", function () {
console.log("client.end"); common.debug("client-side timeout!!");
assert.equal(N+1, count); assert.equal(false, true);
assert.ok(client_ended); });
if (on_complete) on_complete();
tests_run += 1; client.addListener("close", function () {
console.log("client.end");
assert.equal(N+1, count);
assert.ok(client_ended);
if (on_complete) on_complete();
tests_run += 1;
});
}); });
} }

61
test/pummel/test-net-pingpong.js

@ -43,44 +43,45 @@ function pingPongTest (port, host, on_complete) {
socket.server.close(); socket.server.close();
}); });
}); });
server.listen(port, host);
var client = net.createConnection(port, host); server.listen(port, host, function () {
var client = net.createConnection(port, host);
client.setEncoding("utf8"); client.setEncoding("utf8");
client.addListener("connect", function () { client.addListener("connect", function () {
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
client.write("PING"); client.write("PING");
}); });
client.addListener("data", function (data) { client.addListener("data", function (data) {
console.log('client got: ' + data); console.log('client got: ' + data);
assert.equal("PONG", data); assert.equal("PONG", data);
count += 1; count += 1;
if (sent_final_ping) { if (sent_final_ping) {
assert.equal("readOnly", client.readyState); assert.equal("readOnly", client.readyState);
return; return;
} else { } else {
assert.equal("open", client.readyState); assert.equal("open", client.readyState);
} }
if (count < N) { if (count < N) {
client.write("PING"); client.write("PING");
} else { } else {
sent_final_ping = true; sent_final_ping = true;
client.write("PING"); client.write("PING");
client.end(); client.end();
} }
}); });
client.addListener("close", function () { client.addListener("close", function () {
assert.equal(N+1, count); assert.equal(N+1, count);
assert.equal(true, sent_final_ping); assert.equal(true, sent_final_ping);
if (on_complete) on_complete(); if (on_complete) on_complete();
tests_run += 1; tests_run += 1;
});
}); });
} }

59
test/pummel/test-net-throttle.js

@ -3,6 +3,10 @@ assert = common.assert
net = require("net"); net = require("net");
N = 160*1024; // 30kb N = 160*1024; // 30kb
chars_recved = 0;
npauses = 0;
console.log("build big string"); console.log("build big string");
var body = ""; var body = "";
for (var i = 0; i < N; i++) { for (var i = 0; i < N; i++) {
@ -17,38 +21,35 @@ server = net.createServer(function (connection) {
connection.end(); connection.end();
}); });
}); });
server.listen(common.PORT); server.listen(common.PORT, function () {
var paused = false;
client = net.createConnection(common.PORT);
chars_recved = 0; client.setEncoding("ascii");
npauses = 0; client.addListener("data", function (d) {
chars_recved += d.length;
console.log("got " + chars_recved);
if (!paused) {
client.pause();
npauses += 1;
paused = true;
console.log("pause");
x = chars_recved;
setTimeout(function () {
assert.equal(chars_recved, x);
client.resume();
console.log("resume");
paused = false;
}, 100);
}
});
var paused = false; client.addListener("end", function () {
client = net.createConnection(common.PORT); server.close();
client.setEncoding("ascii"); client.end();
client.addListener("data", function (d) { });
chars_recved += d.length;
console.log("got " + chars_recved);
if (!paused) {
client.pause();
npauses += 1;
paused = true;
console.log("pause");
x = chars_recved;
setTimeout(function () {
assert.equal(chars_recved, x);
client.resume();
console.log("resume");
paused = false;
}, 100);
}
}); });
client.addListener("end", function () {
server.close();
client.end();
});
process.addListener("exit", function () { process.addListener("exit", function () {
assert.equal(N, chars_recved); assert.equal(N, chars_recved);

5
test/simple/test-http-full-response.js

@ -23,7 +23,10 @@ function runAb(opts, callback) {
var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/"; var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
exec(command, function (err, stdout, stderr) { exec(command, function (err, stdout, stderr) {
if (err) { if (err) {
console.log("ab not installed? skipping test.\n" + stderr); if (stderr.indexOf("ab") >= 0) {
console.log("ab not installed? skipping test.\n" + stderr);
process.reallyExit(0);
}
process.exit(); process.exit();
return; return;
} }

Loading…
Cancel
Save