Skip to content

Commit

Permalink
test: writable stream ending state
Browse files Browse the repository at this point in the history
Add a test for _writableState.ending, when ending becomes true,
but the stream is not finished/ended yet.

PR-URL: #8707
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Related: #8686
  • Loading branch information
italoacasas authored and Myles Borins committed Nov 17, 2016
1 parent 80a26c7 commit ba4a3ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function WritableState(options, stream) {
// cast to ints.
this.highWaterMark = ~~this.highWaterMark;

// drain event flag.
this.needDrain = false;
// at the start of calling end()
this.ending = false;
Expand Down
34 changes: 34 additions & 0 deletions test/parallel/test-stream-writableState-ending.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

require('../common');

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

const writable = new stream.Writable();

function testStates(ending, finished, ended) {
assert.strictEqual(writable._writableState.ending, ending);
assert.strictEqual(writable._writableState.finished, finished);
assert.strictEqual(writable._writableState.ended, ended);
}

writable._write = (chunk, encoding, cb) => {
// ending, finished, ended start in false.
testStates(false, false, false);
cb();
};

writable.on('finish', () => {
// ending, finished, ended = true.
testStates(true, true, true);
});

writable.end('testing function end()', () => {
// ending, finished, ended = true.
testStates(true, true, true);
});

// ending, ended = true.
// finished = false.
testStates(true, false, true);

0 comments on commit ba4a3ed

Please sign in to comment.