Skip to content

Commit a8c2bb4

Browse files
committed
Fix tests
1 parent 0312343 commit a8c2bb4

File tree

5 files changed

+102
-94
lines changed

5 files changed

+102
-94
lines changed

test/pummel/test-keep-alive.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ function runAb(opts, callback) {
2222
var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
2323
exec(command, function (err, stdout, stderr) {
2424
if (err) {
25-
console.log("ab not installed? skipping test.\n" + stderr);
26-
process.exit();
25+
if (stderr.indexOf("ab") >= 0) {
26+
console.log("ab not installed? skipping test.\n" + stderr);
27+
process.reallyExit(0);
28+
}
2729
return;
2830
}
2931
if (err) throw err;

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

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,45 +43,46 @@ function pingPongTest (port, host, on_complete) {
4343
socket.server.close();
4444
});
4545
});
46-
server.listen(port, host);
4746

48-
var client = net.createConnection(port, host);
47+
server.listen(port, host, function () {
48+
var client = net.createConnection(port, host);
4949

50-
client.setEncoding("utf8");
50+
client.setEncoding("utf8");
5151

52-
client.addListener("connect", function () {
53-
assert.equal("open", client.readyState);
54-
client.write("PING");
55-
});
56-
57-
client.addListener("data", function (data) {
58-
console.log(data);
59-
assert.equal("PONG", data);
60-
assert.equal("open", client.readyState);
52+
client.addListener("connect", function () {
53+
assert.equal("open", client.readyState);
54+
client.write("PING");
55+
});
6156

62-
setTimeout(function () {
57+
client.addListener("data", function (data) {
58+
console.log(data);
59+
assert.equal("PONG", data);
6360
assert.equal("open", client.readyState);
64-
if (count++ < N) {
65-
client.write("PING");
66-
} else {
67-
console.log("closing client");
68-
client.end();
69-
client_ended = true;
70-
}
71-
}, DELAY);
72-
});
7361

74-
client.addListener("timeout", function () {
75-
common.debug("client-side timeout!!");
76-
assert.equal(false, true);
77-
});
62+
setTimeout(function () {
63+
assert.equal("open", client.readyState);
64+
if (count++ < N) {
65+
client.write("PING");
66+
} else {
67+
console.log("closing client");
68+
client.end();
69+
client_ended = true;
70+
}
71+
}, DELAY);
72+
});
7873

79-
client.addListener("close", function () {
80-
console.log("client.end");
81-
assert.equal(N+1, count);
82-
assert.ok(client_ended);
83-
if (on_complete) on_complete();
84-
tests_run += 1;
74+
client.addListener("timeout", function () {
75+
common.debug("client-side timeout!!");
76+
assert.equal(false, true);
77+
});
78+
79+
client.addListener("close", function () {
80+
console.log("client.end");
81+
assert.equal(N+1, count);
82+
assert.ok(client_ended);
83+
if (on_complete) on_complete();
84+
tests_run += 1;
85+
});
8586
});
8687
}
8788

test/pummel/test-net-pingpong.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,44 +43,45 @@ function pingPongTest (port, host, on_complete) {
4343
socket.server.close();
4444
});
4545
});
46-
server.listen(port, host);
4746

48-
var client = net.createConnection(port, host);
47+
server.listen(port, host, function () {
48+
var client = net.createConnection(port, host);
4949

50-
client.setEncoding("utf8");
50+
client.setEncoding("utf8");
5151

52-
client.addListener("connect", function () {
53-
assert.equal("open", client.readyState);
54-
client.write("PING");
55-
});
52+
client.addListener("connect", function () {
53+
assert.equal("open", client.readyState);
54+
client.write("PING");
55+
});
5656

57-
client.addListener("data", function (data) {
58-
console.log('client got: ' + data);
57+
client.addListener("data", function (data) {
58+
console.log('client got: ' + data);
5959

60-
assert.equal("PONG", data);
61-
count += 1;
60+
assert.equal("PONG", data);
61+
count += 1;
6262

63-
if (sent_final_ping) {
64-
assert.equal("readOnly", client.readyState);
65-
return;
66-
} else {
67-
assert.equal("open", client.readyState);
68-
}
63+
if (sent_final_ping) {
64+
assert.equal("readOnly", client.readyState);
65+
return;
66+
} else {
67+
assert.equal("open", client.readyState);
68+
}
6969

70-
if (count < N) {
71-
client.write("PING");
72-
} else {
73-
sent_final_ping = true;
74-
client.write("PING");
75-
client.end();
76-
}
77-
});
70+
if (count < N) {
71+
client.write("PING");
72+
} else {
73+
sent_final_ping = true;
74+
client.write("PING");
75+
client.end();
76+
}
77+
});
7878

79-
client.addListener("close", function () {
80-
assert.equal(N+1, count);
81-
assert.equal(true, sent_final_ping);
82-
if (on_complete) on_complete();
83-
tests_run += 1;
79+
client.addListener("close", function () {
80+
assert.equal(N+1, count);
81+
assert.equal(true, sent_final_ping);
82+
if (on_complete) on_complete();
83+
tests_run += 1;
84+
});
8485
});
8586
}
8687

test/pummel/test-net-throttle.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ assert = common.assert
33
net = require("net");
44
N = 160*1024; // 30kb
55

6+
7+
chars_recved = 0;
8+
npauses = 0;
9+
610
console.log("build big string");
711
var body = "";
812
for (var i = 0; i < N; i++) {
@@ -17,38 +21,35 @@ server = net.createServer(function (connection) {
1721
connection.end();
1822
});
1923
});
20-
server.listen(common.PORT);
21-
22-
23-
chars_recved = 0;
24-
npauses = 0;
25-
24+
server.listen(common.PORT, function () {
25+
var paused = false;
26+
client = net.createConnection(common.PORT);
27+
client.setEncoding("ascii");
28+
client.addListener("data", function (d) {
29+
chars_recved += d.length;
30+
console.log("got " + chars_recved);
31+
if (!paused) {
32+
client.pause();
33+
npauses += 1;
34+
paused = true;
35+
console.log("pause");
36+
x = chars_recved;
37+
setTimeout(function () {
38+
assert.equal(chars_recved, x);
39+
client.resume();
40+
console.log("resume");
41+
paused = false;
42+
}, 100);
43+
}
44+
});
2645

27-
var paused = false;
28-
client = net.createConnection(common.PORT);
29-
client.setEncoding("ascii");
30-
client.addListener("data", function (d) {
31-
chars_recved += d.length;
32-
console.log("got " + chars_recved);
33-
if (!paused) {
34-
client.pause();
35-
npauses += 1;
36-
paused = true;
37-
console.log("pause");
38-
x = chars_recved;
39-
setTimeout(function () {
40-
assert.equal(chars_recved, x);
41-
client.resume();
42-
console.log("resume");
43-
paused = false;
44-
}, 100);
45-
}
46+
client.addListener("end", function () {
47+
server.close();
48+
client.end();
49+
});
4650
});
4751

48-
client.addListener("end", function () {
49-
server.close();
50-
client.end();
51-
});
52+
5253

5354
process.addListener("exit", function () {
5455
assert.equal(N, chars_recved);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ function runAb(opts, callback) {
2323
var command = "ab " + opts + " http://127.0.0.1:" + common.PORT + "/";
2424
exec(command, function (err, stdout, stderr) {
2525
if (err) {
26-
console.log("ab not installed? skipping test.\n" + stderr);
26+
if (stderr.indexOf("ab") >= 0) {
27+
console.log("ab not installed? skipping test.\n" + stderr);
28+
process.reallyExit(0);
29+
}
2730
process.exit();
2831
return;
2932
}

0 commit comments

Comments
 (0)