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 + "/";
exec(command, function (err, stdout, stderr) {
if (err) {
console.log("ab not installed? skipping test.\n" + stderr);
process.exit();
if (stderr.indexOf("ab") >= 0) {
console.log("ab not installed? skipping test.\n" + stderr);
process.reallyExit(0);
}
return;
}
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();
});
});
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 () {
assert.equal("open", client.readyState);
client.write("PING");
});
client.addListener("data", function (data) {
console.log(data);
assert.equal("PONG", data);
assert.equal("open", client.readyState);
client.addListener("connect", function () {
assert.equal("open", client.readyState);
client.write("PING");
});
setTimeout(function () {
client.addListener("data", function (data) {
console.log(data);
assert.equal("PONG", data);
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 () {
common.debug("client-side timeout!!");
assert.equal(false, true);
});
setTimeout(function () {
assert.equal("open", client.readyState);
if (count++ < N) {
client.write("PING");
} else {
console.log("closing client");
client.end();
client_ended = true;
}
}, DELAY);
});
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;
client.addListener("timeout", function () {
common.debug("client-side timeout!!");
assert.equal(false, true);
});
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();
});
});
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 () {
assert.equal("open", client.readyState);
client.write("PING");
});
client.addListener("connect", function () {
assert.equal("open", client.readyState);
client.write("PING");
});
client.addListener("data", function (data) {
console.log('client got: ' + data);
client.addListener("data", function (data) {
console.log('client got: ' + data);
assert.equal("PONG", data);
count += 1;
assert.equal("PONG", data);
count += 1;
if (sent_final_ping) {
assert.equal("readOnly", client.readyState);
return;
} else {
assert.equal("open", client.readyState);
}
if (sent_final_ping) {
assert.equal("readOnly", client.readyState);
return;
} else {
assert.equal("open", client.readyState);
}
if (count < N) {
client.write("PING");
} else {
sent_final_ping = true;
client.write("PING");
client.end();
}
});
if (count < N) {
client.write("PING");
} else {
sent_final_ping = true;
client.write("PING");
client.end();
}
});
client.addListener("close", function () {
assert.equal(N+1, count);
assert.equal(true, sent_final_ping);
if (on_complete) on_complete();
tests_run += 1;
client.addListener("close", function () {
assert.equal(N+1, count);
assert.equal(true, sent_final_ping);
if (on_complete) on_complete();
tests_run += 1;
});
});
}

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

@ -3,6 +3,10 @@ assert = common.assert
net = require("net");
N = 160*1024; // 30kb
chars_recved = 0;
npauses = 0;
console.log("build big string");
var body = "";
for (var i = 0; i < N; i++) {
@ -17,38 +21,35 @@ server = net.createServer(function (connection) {
connection.end();
});
});
server.listen(common.PORT);
chars_recved = 0;
npauses = 0;
server.listen(common.PORT, function () {
var paused = false;
client = net.createConnection(common.PORT);
client.setEncoding("ascii");
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 = net.createConnection(common.PORT);
client.setEncoding("ascii");
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();
});
});
client.addListener("end", function () {
server.close();
client.end();
});
process.addListener("exit", function () {
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 + "/";
exec(command, function (err, stdout, stderr) {
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();
return;
}

Loading…
Cancel
Save