diff options
author | Matteo Collina <hello@matteocollina.com> | 2018-08-09 14:02:33 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-08-21 22:36:13 -0700 |
commit | 98cf84f2c9d13386362386eac6089bc356c017b2 (patch) | |
tree | 1708476e69dd9e1dff187514b6508c58b6a88310 /test/parallel/test-stream-once-readable-pipe.js | |
parent | 588fb05e7858e11e556d5a50213e293a2a66e631 (diff) | |
download | android-node-v8-98cf84f2c9d13386362386eac6089bc356c017b2.tar.gz android-node-v8-98cf84f2c9d13386362386eac6089bc356c017b2.tar.bz2 android-node-v8-98cf84f2c9d13386362386eac6089bc356c017b2.zip |
stream: restore flow if there are 'data' handlers after once('readable')
Fixes: https://github.com/nodejs/node/issues/21398
See: https://github.com/nodejs/node/pull/21696
PR-URL: https://github.com/nodejs/node/pull/22209
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mathias Buus <mathiasbuus@gmail.com>
Diffstat (limited to 'test/parallel/test-stream-once-readable-pipe.js')
-rw-r--r-- | test/parallel/test-stream-once-readable-pipe.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/parallel/test-stream-once-readable-pipe.js b/test/parallel/test-stream-once-readable-pipe.js new file mode 100644 index 0000000000..e8f4e9422d --- /dev/null +++ b/test/parallel/test-stream-once-readable-pipe.js @@ -0,0 +1,61 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { Readable, Writable } = require('stream'); + +// This test ensures that if have 'readable' listener +// on Readable instance it will not disrupt the pipe. + +{ + let receivedData = ''; + const w = new Writable({ + write: (chunk, env, callback) => { + receivedData += chunk; + callback(); + }, + }); + + const data = ['foo', 'bar', 'baz']; + const r = new Readable({ + read: () => {}, + }); + + r.once('readable', common.mustCall()); + + r.pipe(w); + r.push(data[0]); + r.push(data[1]); + r.push(data[2]); + r.push(null); + + w.on('finish', common.mustCall(() => { + assert.strictEqual(receivedData, data.join('')); + })); +} + +{ + let receivedData = ''; + const w = new Writable({ + write: (chunk, env, callback) => { + receivedData += chunk; + callback(); + }, + }); + + const data = ['foo', 'bar', 'baz']; + const r = new Readable({ + read: () => {}, + }); + + r.pipe(w); + r.push(data[0]); + r.push(data[1]); + r.push(data[2]); + r.push(null); + r.once('readable', common.mustCall()); + + w.on('finish', common.mustCall(() => { + assert.strictEqual(receivedData, data.join('')); + })); +} |