mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 20:34:33 +00:00

Avoid trying to emit 'readable' due to the fact that state.length is always >= state.highWaterMark if highWaterMark is 0. Therefore upon .read(0) call (through .on('readable')) stream assumed that it has enough data to emit 'readable' even though state.length === 0 instead of issuing _read(). Which led to the TTY not recognizing that someone is waiting for the input. Fixes: https://github.com/nodejs/node/issues/20503 Refs: https://github.com/nodejs/node/pull/18372 PR-URL: https://github.com/nodejs/node/pull/21690 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
31 lines
831 B
JavaScript
31 lines
831 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
// This test ensures that Readable stream will call _read() for streams
|
|
// with highWaterMark === 0 upon .read(0) instead of just trying to
|
|
// emit 'readable' event.
|
|
|
|
const assert = require('assert');
|
|
const { Readable } = require('stream');
|
|
|
|
const r = new Readable({
|
|
// must be called only once upon setting 'readable' listener
|
|
read: common.mustCall(),
|
|
highWaterMark: 0,
|
|
});
|
|
|
|
let pushedNull = false;
|
|
// this will trigger read(0) but must only be called after push(null)
|
|
// because the we haven't pushed any data
|
|
r.on('readable', common.mustCall(() => {
|
|
assert.strictEqual(r.read(), null);
|
|
assert.strictEqual(pushedNull, true);
|
|
}));
|
|
r.on('end', common.mustCall());
|
|
process.nextTick(() => {
|
|
assert.strictEqual(r.read(), null);
|
|
pushedNull = true;
|
|
r.push(null);
|
|
});
|