0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/mjsunit/test-tcp-throttle-kernel-buffer.js

57 lines
1.1 KiB
JavaScript
Raw Normal View History

process.mixin(require("./common"));
tcp = require("tcp");
PORT = 20444;
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);
2009-09-28 16:08:09 +02:00
server = tcp.createServer(function (connection) {
connection.addListener("connect", function () {
connection.write(body);
2009-08-19 17:28:41 +02:00
connection.close();
});
});
server.listen(PORT);
chars_recved = 0;
npauses = 0;
2009-08-26 18:22:00 +02:00
var paused = false;
2009-09-28 16:08:09 +02:00
client = tcp.createConnection(PORT);
2009-08-26 18:22:00 +02:00
client.setEncoding("ascii");
client.addListener("data", function (d) {
2009-08-26 18:22:00 +02:00
chars_recved += d.length;
puts("got " + chars_recved);
if (!paused) {
client.readPause();
npauses += 1;
paused = true;
puts("pause");
x = chars_recved;
setTimeout(function () {
assert.equal(chars_recved, x);
2009-08-26 18:22:00 +02:00
client.readResume();
puts("resume");
paused = false;
}, 100);
}
});
client.addListener("end", function () {
2009-08-26 18:22:00 +02:00
server.close();
client.close();
});
process.addListener("exit", function () {
assert.equal(N, chars_recved);
assert.equal(true, npauses > 2);
});