mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
04b4d15b39
Many of the tests use variables to track when callback functions are invoked or events are emitted. These variables are then asserted on process exit. This commit replaces this pattern in straightforward cases with common.mustCall(). This makes the tests easier to reason about, leads to a net reduction in lines of code, and uncovered a few bugs in tests. This commit also replaces some callbacks that should never be called with common.fail(). PR-URL: https://github.com/nodejs/node/pull/7753 Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
if (!common.hasCrypto) {
|
|
common.skip('missing crypto');
|
|
return;
|
|
}
|
|
var tls = require('tls');
|
|
|
|
var fs = require('fs');
|
|
|
|
var buf = Buffer.allocUnsafe(10000);
|
|
var received = 0;
|
|
var maxChunk = 768;
|
|
|
|
var server = tls.createServer({
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
}, function(c) {
|
|
// Lower and upper limits
|
|
assert(!c.setMaxSendFragment(511));
|
|
assert(!c.setMaxSendFragment(16385));
|
|
|
|
// Correct fragment size
|
|
assert(c.setMaxSendFragment(maxChunk));
|
|
|
|
c.end(buf);
|
|
}).listen(0, common.mustCall(function() {
|
|
var c = tls.connect(this.address().port, {
|
|
rejectUnauthorized: false
|
|
}, common.mustCall(function() {
|
|
c.on('data', function(chunk) {
|
|
assert(chunk.length <= maxChunk);
|
|
received += chunk.length;
|
|
});
|
|
|
|
// Ensure that we receive 'end' event anyway
|
|
c.on('end', common.mustCall(function() {
|
|
c.destroy();
|
|
server.close();
|
|
assert.strictEqual(received, buf.length);
|
|
}));
|
|
}));
|
|
}));
|