mirror of https://github.com/lukechilds/node.git
Ryan Dahl
15 years ago
8 changed files with 117 additions and 111 deletions
@ -0,0 +1,67 @@ |
|||
process.mixin(require("../common")); |
|||
tcp = require("tcp"); |
|||
N = 200; |
|||
|
|||
server = tcp.createServer(function (connection) { |
|||
function write (j) { |
|||
if (j >= N) { |
|||
connection.close(); |
|||
return; |
|||
} |
|||
setTimeout(function () { |
|||
connection.write("C"); |
|||
write(j+1); |
|||
}, 10); |
|||
} |
|||
write(0); |
|||
}); |
|||
server.listen(PORT); |
|||
|
|||
|
|||
recv = ""; |
|||
chars_recved = 0; |
|||
|
|||
client = tcp.createConnection(PORT); |
|||
client.setEncoding("ascii"); |
|||
client.addListener("data", function (d) { |
|||
print(d); |
|||
recv += d; |
|||
}); |
|||
|
|||
setTimeout(function () { |
|||
chars_recved = recv.length; |
|||
puts("pause at: " + chars_recved); |
|||
assert.equal(true, chars_recved > 1); |
|||
client.pause(); |
|||
setTimeout(function () { |
|||
puts("resume at: " + chars_recved); |
|||
assert.equal(chars_recved, recv.length); |
|||
client.resume(); |
|||
|
|||
setTimeout(function () { |
|||
chars_recved = recv.length; |
|||
puts("pause at: " + chars_recved); |
|||
client.pause(); |
|||
|
|||
setTimeout(function () { |
|||
puts("resume at: " + chars_recved); |
|||
assert.equal(chars_recved, recv.length); |
|||
client.resume(); |
|||
|
|||
}, 500); |
|||
|
|||
}, 500); |
|||
|
|||
}, 500); |
|||
|
|||
}, 500); |
|||
|
|||
client.addListener("end", function () { |
|||
server.close(); |
|||
client.close(); |
|||
}); |
|||
|
|||
process.addListener("exit", function () { |
|||
assert.equal(N, recv.length); |
|||
debug("Exit"); |
|||
}); |
@ -1,55 +0,0 @@ |
|||
process.mixin(require("../common")); |
|||
tcp = require("tcp"); |
|||
N = 30*1024; // 500kb
|
|||
|
|||
puts("build big string"); |
|||
var body = ""; |
|||
for (var i = 0; i < N; i++) { |
|||
body += "C"; |
|||
} |
|||
|
|||
puts("start server on port " + PORT); |
|||
|
|||
server = tcp.createServer(function (connection) { |
|||
connection.addListener("connect", function () { |
|||
connection.write(body); |
|||
connection.close(); |
|||
}); |
|||
}); |
|||
server.listen(PORT); |
|||
|
|||
|
|||
chars_recved = 0; |
|||
npauses = 0; |
|||
|
|||
|
|||
var paused = false; |
|||
client = tcp.createConnection(PORT); |
|||
client.setEncoding("ascii"); |
|||
client.addListener("data", function (d) { |
|||
chars_recved += d.length; |
|||
puts("got " + chars_recved); |
|||
if (!paused) { |
|||
client.pause(); |
|||
npauses += 1; |
|||
paused = true; |
|||
puts("pause"); |
|||
x = chars_recved; |
|||
setTimeout(function () { |
|||
assert.equal(chars_recved, x); |
|||
client.resume(); |
|||
puts("resume"); |
|||
paused = false; |
|||
}, 100); |
|||
} |
|||
}); |
|||
|
|||
client.addListener("end", function () { |
|||
server.close(); |
|||
client.close(); |
|||
}); |
|||
|
|||
process.addListener("exit", function () { |
|||
assert.equal(N, chars_recved); |
|||
assert.equal(true, npauses > 2); |
|||
}); |
Loading…
Reference in new issue