Fix tests
This commit is contained in:
parent
03123435e0
commit
a8c2bb41af
@ -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;
|
||||||
|
@ -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);
|
|
||||||
client.write("PING");
|
|
||||||
});
|
|
||||||
|
|
||||||
client.addListener("data", function (data) {
|
|
||||||
console.log(data);
|
|
||||||
assert.equal("PONG", data);
|
|
||||||
assert.equal("open", client.readyState);
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
assert.equal("open", client.readyState);
|
assert.equal("open", client.readyState);
|
||||||
if (count++ < N) {
|
client.write("PING");
|
||||||
client.write("PING");
|
});
|
||||||
} else {
|
|
||||||
console.log("closing client");
|
|
||||||
client.end();
|
|
||||||
client_ended = true;
|
|
||||||
}
|
|
||||||
}, DELAY);
|
|
||||||
});
|
|
||||||
|
|
||||||
client.addListener("timeout", function () {
|
client.addListener("data", function (data) {
|
||||||
common.debug("client-side timeout!!");
|
console.log(data);
|
||||||
assert.equal(false, true);
|
assert.equal("PONG", data);
|
||||||
});
|
assert.equal("open", client.readyState);
|
||||||
|
|
||||||
client.addListener("close", function () {
|
setTimeout(function () {
|
||||||
console.log("client.end");
|
assert.equal("open", client.readyState);
|
||||||
assert.equal(N+1, count);
|
if (count++ < N) {
|
||||||
assert.ok(client_ended);
|
client.write("PING");
|
||||||
if (on_complete) on_complete();
|
} else {
|
||||||
tests_run += 1;
|
console.log("closing client");
|
||||||
|
client.end();
|
||||||
|
client_ended = true;
|
||||||
|
}
|
||||||
|
}, DELAY);
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
|
||||||
client.write("PING");
|
|
||||||
});
|
|
||||||
|
|
||||||
client.addListener("data", function (data) {
|
|
||||||
console.log('client got: ' + data);
|
|
||||||
|
|
||||||
assert.equal("PONG", data);
|
|
||||||
count += 1;
|
|
||||||
|
|
||||||
if (sent_final_ping) {
|
|
||||||
assert.equal("readOnly", client.readyState);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
assert.equal("open", client.readyState);
|
assert.equal("open", client.readyState);
|
||||||
}
|
|
||||||
|
|
||||||
if (count < N) {
|
|
||||||
client.write("PING");
|
client.write("PING");
|
||||||
} else {
|
});
|
||||||
sent_final_ping = true;
|
|
||||||
client.write("PING");
|
|
||||||
client.end();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
client.addListener("close", function () {
|
client.addListener("data", function (data) {
|
||||||
assert.equal(N+1, count);
|
console.log('client got: ' + data);
|
||||||
assert.equal(true, sent_final_ping);
|
|
||||||
if (on_complete) on_complete();
|
assert.equal("PONG", data);
|
||||||
tests_run += 1;
|
count += 1;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.addListener("close", function () {
|
||||||
|
assert.equal(N+1, count);
|
||||||
|
assert.equal(true, sent_final_ping);
|
||||||
|
if (on_complete) on_complete();
|
||||||
|
tests_run += 1;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
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 () {
|
||||||
chars_recved = 0;
|
server.close();
|
||||||
npauses = 0;
|
client.end();
|
||||||
|
});
|
||||||
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
|
|
||||||
process.addListener("exit", function () {
|
process.addListener("exit", function () {
|
||||||
assert.equal(N, chars_recved);
|
assert.equal(N, chars_recved);
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user