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 <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Related: #8686
  • Loading branch information
italoacasas authored and mcollina committed Oct 28, 2016
1 parent f12338d commit fd16eed
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';

const common = 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 fd16eed

Please sign in to comment.