2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2011-02-01 00:38:05 +00:00
|
|
|
// Server sends a large string. Client counts bytes and pauses every few
|
|
|
|
// seconds. Makes sure that pause and resume work properly.
|
2012-08-30 13:14:37 +00:00
|
|
|
|
2016-12-30 23:38:06 +00:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2015-03-04 01:11:21 +00:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
2016-05-11 19:34:52 +00:00
|
|
|
common.skip('missing crypto');
|
2015-07-07 15:25:55 +00:00
|
|
|
return;
|
2015-03-04 01:11:21 +00:00
|
|
|
}
|
2016-12-30 23:38:06 +00:00
|
|
|
const tls = require('tls');
|
|
|
|
const fs = require('fs');
|
2011-02-01 00:38:05 +00:00
|
|
|
|
|
|
|
process.stdout.write('build body...');
|
2017-01-08 13:19:00 +00:00
|
|
|
const body = 'hello world\n'.repeat(1024 * 1024);
|
2011-02-01 00:38:05 +00:00
|
|
|
process.stdout.write('done\n');
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const options = {
|
2011-02-01 00:38:05 +00:00
|
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
|
|
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem')
|
|
|
|
};
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = tls.Server(options, common.mustCall(function(socket) {
|
2011-02-01 00:38:05 +00:00
|
|
|
socket.end(body);
|
2016-07-15 19:43:24 +00:00
|
|
|
}));
|
2011-02-01 00:38:05 +00:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let recvCount = 0;
|
2011-02-01 00:38:05 +00:00
|
|
|
|
|
|
|
server.listen(common.PORT, function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const client = tls.connect({
|
2012-08-30 14:43:20 +00:00
|
|
|
port: common.PORT,
|
|
|
|
rejectUnauthorized: false
|
|
|
|
});
|
2011-02-01 00:38:05 +00:00
|
|
|
|
|
|
|
client.on('data', function(d) {
|
2011-02-03 20:17:26 +00:00
|
|
|
process.stdout.write('.');
|
2011-02-01 00:38:05 +00:00
|
|
|
recvCount += d.length;
|
|
|
|
|
|
|
|
client.pause();
|
2011-10-04 22:08:18 +00:00
|
|
|
process.nextTick(function() {
|
2011-02-01 00:38:05 +00:00
|
|
|
client.resume();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
client.on('close', function() {
|
2011-02-03 20:17:26 +00:00
|
|
|
console.error('close');
|
2011-02-01 00:38:05 +00:00
|
|
|
server.close();
|
|
|
|
clearTimeout(timeout);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2011-02-03 20:17:26 +00:00
|
|
|
function displayCounts() {
|
|
|
|
console.log('body.length: %d', body.length);
|
|
|
|
console.log(' recvCount: %d', recvCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const timeout = setTimeout(displayCounts, 10 * 1000);
|
2011-02-01 00:38:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
2011-02-03 20:17:26 +00:00
|
|
|
displayCounts();
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(body.length, recvCount);
|
2011-02-01 00:38:05 +00:00
|
|
|
});
|