diff options
author | Mathias Buus <mathiasbuus@gmail.com> | 2018-08-21 20:05:12 +0200 |
---|---|---|
committer | Mathias Buus <mathiasbuus@gmail.com> | 2018-10-30 15:17:40 +0100 |
commit | f24b070cb7fb04df6249fab5264df2146e2b6cac (patch) | |
tree | 46438985fb9676a4e5b951a00f8a30693f25c280 /test | |
parent | cd1193d9ed83c37a431a19ae33bbf5e25ec15d65 (diff) | |
download | android-node-v8-f24b070cb7fb04df6249fab5264df2146e2b6cac.tar.gz android-node-v8-f24b070cb7fb04df6249fab5264df2146e2b6cac.tar.bz2 android-node-v8-f24b070cb7fb04df6249fab5264df2146e2b6cac.zip |
stream: add auto-destroy mode
PR-URL: https://github.com/nodejs/node/pull/22795
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-stream-auto-destroy.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/parallel/test-stream-auto-destroy.js b/test/parallel/test-stream-auto-destroy.js new file mode 100644 index 0000000000..7bce8a5636 --- /dev/null +++ b/test/parallel/test-stream-auto-destroy.js @@ -0,0 +1,84 @@ +'use strict'; +const common = require('../common'); +const stream = require('stream'); +const assert = require('assert'); + +{ + const r = new stream.Readable({ + autoDestroy: true, + read() { + this.push('hello'); + this.push('world'); + this.push(null); + }, + destroy: common.mustCall((err, cb) => cb()) + }); + + let ended = false; + + r.resume(); + + r.on('end', common.mustCall(() => { + ended = true; + })); + + r.on('close', common.mustCall(() => { + assert(ended); + })); +} + +{ + const w = new stream.Writable({ + autoDestroy: true, + write(data, enc, cb) { + cb(null); + }, + destroy: common.mustCall((err, cb) => cb()) + }); + + let finished = false; + + w.write('hello'); + w.write('world'); + w.end(); + + w.on('finish', common.mustCall(() => { + finished = true; + })); + + w.on('close', common.mustCall(() => { + assert(finished); + })); +} + +{ + const t = new stream.Transform({ + autoDestroy: true, + transform(data, enc, cb) { + cb(null, data); + }, + destroy: common.mustCall((err, cb) => cb()) + }); + + let ended = false; + let finished = false; + + t.write('hello'); + t.write('world'); + t.end(); + + t.resume(); + + t.on('end', common.mustCall(() => { + ended = true; + })); + + t.on('finish', common.mustCall(() => { + finished = true; + })); + + t.on('close', common.mustCall(() => { + assert(ended); + assert(finished); + })); +} |