Skip to content

Commit

Permalink
test: refactor test-https-truncate
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Trott authored and italoacasas committed Jan 18, 2017
1 parent 7af0fde commit 01df523
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/parallel/test-https-truncate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';
const common = require('../common');
const assert = require('assert');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

const assert = require('assert');
const https = require('https');

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

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

httpsTest();

Expand All @@ -36,19 +37,18 @@ function httpsTest() {
}


function test(res) {
res.on('end', function() {
const test = common.mustCall(function(res) {
res.on('end', common.mustCall(function() {
assert.strictEqual(res._readableState.length, 0);
assert.strictEqual(bytes, data.length);
console.log('ok');
});
}));

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

0 comments on commit 01df523

Please sign in to comment.