node/test/pummel/test-tls-throttle.js
Gibson Fahnestock 3d2aef3979 test: s/assert.equal/assert.strictEqual/
Use assert.strictEqual instead of assert.equal in tests, manually
convert types where necessary.

PR-URL: https://github.com/nodejs/node/pull/10698
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2017-01-11 14:19:26 +00:00

68 lines
1.4 KiB
JavaScript

'use strict';
// Server sends a large string. Client counts bytes and pauses every few
// seconds. Makes sure that pause and resume work properly.
const common = require('../common');
const assert = require('assert');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
const tls = require('tls');
const fs = require('fs');
process.stdout.write('build body...');
const body = 'hello world\n'.repeat(1024 * 1024);
process.stdout.write('done\n');
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem')
};
const server = tls.Server(options, common.mustCall(function(socket) {
socket.end(body);
}));
let recvCount = 0;
server.listen(common.PORT, function() {
const client = tls.connect({
port: common.PORT,
rejectUnauthorized: false
});
client.on('data', function(d) {
process.stdout.write('.');
recvCount += d.length;
client.pause();
process.nextTick(function() {
client.resume();
});
});
client.on('close', function() {
console.error('close');
server.close();
clearTimeout(timeout);
});
});
function displayCounts() {
console.log('body.length: %d', body.length);
console.log(' recvCount: %d', recvCount);
}
const timeout = setTimeout(displayCounts, 10 * 1000);
process.on('exit', function() {
displayCounts();
assert.strictEqual(body.length, recvCount);
});