Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streams: add test for _readableState.readingMore | #8685 #9868

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
Add reading and readingMore tests for 'readable' event
  • Loading branch information
chmln committed Dec 9, 2016
commit 466c083a718d2297c27d337feba624416b71e7af
30 changes: 20 additions & 10 deletions test/parallel/test-stream-readable-reading-readingMore.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@ readable.on('data', common.mustCall((data) => {
assert.strictEqual(state.reading, !state.ended);
}, 2));

readable.on('end', common.mustCall(() => {
// End of stream; _readableState.reading is false
function onStreamEnd() {
// End of stream; state.reading is false
// And so should be readingMore.
assert.strictEqual(state.readingMore, false);
assert.strictEqual(state.reading, false);
}));
}

readable.on('readable', common.mustCall(() => {
// 'readable' always gets called before 'end'
// since 'end' hasn't been emitted, more data could be incoming
assert.strictEqual(state.readingMore, true);

// if the stream has ended, we shouldn't be reading
assert.strictEqual(state.ended, !state.reading);

if (readable.read() === null) // reached end of stream
process.nextTick(common.mustCall(onStreamEnd, 1));
}, 2));

readable.on('end', common.mustCall(onStreamEnd));

readable.push('pushed');

Expand All @@ -39,17 +53,13 @@ readable.read(6);

// reading
assert.strictEqual(state.reading, true);
assert.strictEqual(state.readingMore, true);

// resume emitting 'data' events
readable.resume();

// add chunk to front
readable.unshift('unshifted');
readable.push(null); // end

process.nextTick(() => {
// Finished reading. _readableState.reading is false.
// readingMore then should be false as well.
assert.strictEqual(state.readingMore, false);
assert.strictEqual(state.reading, false);
});
// end
readable.push(null);