test: writable stream ending state
Add a test for _writableState.ending, when ending becomes true, but the stream is not finished/ended yet. PR-URL: https://github.com/nodejs/node/pull/8707 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Related: https://github.com/nodejs/node/issues/8686
This commit is contained in:
parent
f12338ddb0
commit
fd16eed8ea
@ -43,6 +43,7 @@ function WritableState(options, stream) {
|
|||||||
// cast to ints.
|
// cast to ints.
|
||||||
this.highWaterMark = ~~this.highWaterMark;
|
this.highWaterMark = ~~this.highWaterMark;
|
||||||
|
|
||||||
|
// drain event flag.
|
||||||
this.needDrain = false;
|
this.needDrain = false;
|
||||||
// at the start of calling end()
|
// at the start of calling end()
|
||||||
this.ending = false;
|
this.ending = false;
|
||||||
|
34
test/parallel/test-stream-writableState-ending.js
Normal file
34
test/parallel/test-stream-writableState-ending.js
Normal file
@ -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);
|
Loading…
x
Reference in New Issue
Block a user