node/test/parallel/test-stream2-large-read-stall.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

56 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
// If everything aligns so that you do a read(n) of exactly the
// remaining buffer, then make sure that 'end' still emits.
const READSIZE = 100;
const PUSHSIZE = 20;
const PUSHCOUNT = 1000;
const HWM = 50;
const Readable = require('stream').Readable;
const r = new Readable({
highWaterMark: HWM
});
const rs = r._readableState;
r._read = push;
r.on('readable', function() {
console.error('>> readable');
let ret;
do {
console.error(' > read(%d)', READSIZE);
ret = r.read(READSIZE);
console.error(' < %j (%d remain)', ret && ret.length, rs.length);
} while (ret && ret.length === READSIZE);
console.error('<< after read()',
ret && ret.length,
rs.needReadable,
rs.length);
});
r.on('end', common.mustCall(function() {}));
let pushes = 0;
function push() {
if (pushes > PUSHCOUNT)
return;
if (pushes++ === PUSHCOUNT) {
console.error(' push(EOF)');
return r.push(null);
}
console.error(' push #%d', pushes);
if (r.push(Buffer.allocUnsafe(PUSHSIZE)))
setTimeout(push, 1);
}
process.on('exit', function() {
assert.equal(pushes, PUSHCOUNT + 1);
});