mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
test: add regression test for unpipe()
Since 2e568d9 there is a bug where unpiping a stream
from a readable stream that has `_readableState.pipesCount > 1`
will cause it to remove the first stream in the
`_.readableState.pipes` array no matter where in the list the
`dest` stream was.
PR-URL: https://github.com/nodejs/node/pull/9171
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
This commit is contained in:
1 parent
f4b766f5b7
commit
6072326009
1 file changed
+30
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const { Readable, Writable } = require('stream');
|
||||
|
||||
const source = Readable({read: () => {}});
|
||||
const dest1 = Writable({write: () => {}});
|
||||
const dest2 = Writable({write: () => {}});
|
||||
|
||||
source.pipe(dest1);
|
||||
source.pipe(dest2);
|
||||
|
||||
dest1.on('unpipe', common.mustCall(() => {}));
|
||||
dest2.on('unpipe', common.mustCall(() => {}));
|
||||
|
||||
assert.strictEqual(source._readableState.pipes[0], dest1);
|
||||
assert.strictEqual(source._readableState.pipes[1], dest2);
|
||||
assert.strictEqual(source._readableState.pipes.length, 2);
|
||||
|
||||
// Should be able to unpipe them in the reverse order that they were piped.
|
||||
|
||||
source.unpipe(dest2);
|
||||
|
||||
assert.strictEqual(source._readableState.pipes, dest1);
|
||||
assert.notStrictEqual(source._readableState.pipes, dest2);
|
||||
|
||||
source.unpipe(dest1);
|
||||
|
||||
assert.strictEqual(source._readableState.pipes, null);
|
||||
Reference in new issue
Block a user