Skip to content

Commit d9c3364

Browse files
Niels NielsenMyles Borins
Niels Nielsen
authored and
Myles Borins
committed
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. Ref: #9553 PR-URL: #9171 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Myles Borins <[email protected]>
1 parent 9b9762c commit d9c3364

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
const Stream = require('stream');
6+
const Readable = Stream.Readable;
7+
const Writable = Stream.Writable;
8+
9+
const source = Readable({read: () => {}});
10+
const dest1 = Writable({write: () => {}});
11+
const dest2 = Writable({write: () => {}});
12+
13+
source.pipe(dest1);
14+
source.pipe(dest2);
15+
16+
dest1.on('unpipe', common.mustCall(() => {}));
17+
dest2.on('unpipe', common.mustCall(() => {}));
18+
19+
assert.strictEqual(source._readableState.pipes[0], dest1);
20+
assert.strictEqual(source._readableState.pipes[1], dest2);
21+
assert.strictEqual(source._readableState.pipes.length, 2);
22+
23+
// Should be able to unpipe them in the reverse order that they were piped.
24+
25+
source.unpipe(dest2);
26+
27+
assert.strictEqual(source._readableState.pipes, dest1);
28+
assert.notStrictEqual(source._readableState.pipes, dest2);
29+
30+
source.unpipe(dest1);
31+
32+
assert.strictEqual(source._readableState.pipes, null);

0 commit comments

Comments
 (0)