Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 13, 2010
1 parent 0312343 commit a8c2bb4
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 94 deletions.
6 changes: 4 additions & 2 deletions test/pummel/test-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 33 additions & 32 deletions test/pummel/test-net-pingpong-delay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
}

Expand Down
61 changes: 31 additions & 30 deletions test/pummel/test-net-pingpong.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
}

Expand Down
59 changes: 30 additions & 29 deletions test/pummel/test-net-throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion test/simple/test-http-full-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a8c2bb4

Please sign in to comment.