Skip to content

Commit c60b2ac

Browse files
Trottitaloacasas
authored andcommitted
test: refactor test-https-truncate
* use common.mustCall() where appropriate * Buffer.allocUnsafe() -> Buffer.alloc() * do crypto check before loading any additional modules * specify 1ms duration for `setTimeout()` PR-URL: nodejs#10225 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 92b49f1 commit c60b2ac

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

test/parallel/test-https-truncate.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict';
22
const common = require('../common');
3-
const assert = require('assert');
43

54
if (!common.hasCrypto) {
65
common.skip('missing crypto');
76
return;
87
}
8+
9+
const assert = require('assert');
910
const https = require('https');
1011

1112
const fs = require('fs');
@@ -14,7 +15,7 @@ const key = fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem');
1415
const cert = fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem');
1516

1617
// number of bytes discovered empirically to trigger the bug
17-
const data = Buffer.allocUnsafe(1024 * 32 + 1);
18+
const data = Buffer.alloc(1024 * 32 + 1);
1819

1920
httpsTest();
2021

@@ -36,19 +37,18 @@ function httpsTest() {
3637
}
3738

3839

39-
function test(res) {
40-
res.on('end', function() {
40+
const test = common.mustCall(function(res) {
41+
res.on('end', common.mustCall(function() {
4142
assert.strictEqual(res._readableState.length, 0);
4243
assert.strictEqual(bytes, data.length);
43-
console.log('ok');
44-
});
44+
}));
4545

4646
// Pause and then resume on each chunk, to ensure that there will be
4747
// a lone byte hanging out at the very end.
4848
let bytes = 0;
4949
res.on('data', function(chunk) {
5050
bytes += chunk.length;
5151
this.pause();
52-
setTimeout(this.resume.bind(this));
52+
setTimeout(this.resume.bind(this), 1);
5353
});
54-
}
54+
});

0 commit comments

Comments
 (0)