2010-12-05 07:20:34 +08:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');;
|
2010-12-03 09:03:18 +08:00
|
|
|
net = require('net');
|
|
|
|
N = 160 * 1024; // 30kb
|
2010-03-03 13:14:23 +08:00
|
|
|
|
2010-08-13 23:54:40 +08:00
|
|
|
|
|
|
|
chars_recved = 0;
|
|
|
|
npauses = 0;
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('build big string');
|
|
|
|
var body = '';
|
2010-03-03 13:14:23 +08:00
|
|
|
for (var i = 0; i < N; i++) {
|
2010-12-03 09:03:18 +08:00
|
|
|
body += 'C';
|
2010-03-03 13:14:23 +08:00
|
|
|
}
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('start server on port ' + common.PORT);
|
2009-08-10 00:49:51 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
server = net.createServer(function(connection) {
|
|
|
|
connection.addListener('connect', function() {
|
2010-03-03 13:14:23 +08:00
|
|
|
assert.equal(false, connection.write(body));
|
2010-04-09 01:44:22 +08:00
|
|
|
connection.end();
|
2010-03-03 13:14:23 +08:00
|
|
|
});
|
2009-08-10 00:49:51 +08:00
|
|
|
});
|
2010-12-03 09:03:18 +08:00
|
|
|
server.listen(common.PORT, function() {
|
2010-08-13 23:54:40 +08:00
|
|
|
var paused = false;
|
|
|
|
client = net.createConnection(common.PORT);
|
2010-12-03 09:03:18 +08:00
|
|
|
client.setEncoding('ascii');
|
|
|
|
client.addListener('data', function(d) {
|
2010-08-13 23:54:40 +08:00
|
|
|
chars_recved += d.length;
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('got ' + chars_recved);
|
2010-08-13 23:54:40 +08:00
|
|
|
if (!paused) {
|
|
|
|
client.pause();
|
|
|
|
npauses += 1;
|
|
|
|
paused = true;
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('pause');
|
2010-08-13 23:54:40 +08:00
|
|
|
x = chars_recved;
|
2010-12-03 09:03:18 +08:00
|
|
|
setTimeout(function() {
|
2010-08-13 23:54:40 +08:00
|
|
|
assert.equal(chars_recved, x);
|
|
|
|
client.resume();
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('resume');
|
2010-08-13 23:54:40 +08:00
|
|
|
paused = false;
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
});
|
2010-03-03 13:14:23 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
client.addListener('end', function() {
|
2010-08-13 23:54:40 +08:00
|
|
|
server.close();
|
|
|
|
client.end();
|
|
|
|
});
|
2010-03-03 13:14:23 +08:00
|
|
|
});
|
2009-08-27 00:22:00 +08:00
|
|
|
|
2010-08-13 23:54:40 +08:00
|
|
|
|
2009-08-10 00:49:51 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
process.addListener('exit', function() {
|
2010-03-03 13:14:23 +08:00
|
|
|
assert.equal(N, chars_recved);
|
|
|
|
assert.equal(true, npauses > 2);
|
2009-08-27 00:51:04 +08:00
|
|
|
});
|