diff options
author | Robert Nagy <ronagy@icloud.com> | 2019-07-16 00:03:23 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-16 21:33:53 -0700 |
commit | 4a2bd69db99c1bb8692e1f653edcb225fbc23032 (patch) | |
tree | b90971ab2b513dcf3f69758113d72661ea017e16 /test/parallel/test-stream2-writable.js | |
parent | a890771cd0a31bda055fc71741ace7822bc678dd (diff) | |
download | android-node-v8-4a2bd69db99c1bb8692e1f653edcb225fbc23032.tar.gz android-node-v8-4a2bd69db99c1bb8692e1f653edcb225fbc23032.tar.bz2 android-node-v8-4a2bd69db99c1bb8692e1f653edcb225fbc23032.zip |
stream: fix destroy() behavior
Ensure errorEmitted is always set. Only emit 'error' once.
PR-URL: https://github.com/nodejs/node/pull/29058
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-stream2-writable.js')
-rw-r--r-- | test/parallel/test-stream2-writable.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/parallel/test-stream2-writable.js b/test/parallel/test-stream2-writable.js index 262606d906..b20f5d3f18 100644 --- a/test/parallel/test-stream2-writable.js +++ b/test/parallel/test-stream2-writable.js @@ -402,3 +402,42 @@ const helloWorldBuffer = Buffer.from('hello world'); w.write(Buffer.allocUnsafe(1)); w.end(Buffer.allocUnsafe(0)); } + +{ + // Verify that error is only emitted once when failing in _finish. + const w = new W(); + + w._final = common.mustCall(function(cb) { + cb(new Error('test')); + }); + w.on('error', common.mustCall((err) => { + assert.strictEqual(w._writableState.errorEmitted, true); + assert.strictEqual(err.message, 'test'); + w.on('error', common.mustNotCall()); + w.destroy(new Error()); + })); + w.end(); +} + +{ + // Verify that error is only emitted once when failing in write. + const w = new W(); + w.on('error', common.mustCall((err) => { + assert.strictEqual(w._writableState.errorEmitted, true); + assert.strictEqual(err.code, 'ERR_STREAM_NULL_VALUES'); + })); + w.write(null); + w.destroy(new Error()); +} + +{ + // Verify that error is only emitted once when failing in write after end. + const w = new W(); + w.on('error', common.mustCall((err) => { + assert.strictEqual(w._writableState.errorEmitted, true); + assert.strictEqual(err.code, 'ERR_STREAM_WRITE_AFTER_END'); + })); + w.end(); + w.write('hello'); + w.destroy(new Error()); +} |