Skip to content

Commit

Permalink
test: add regression test for unpipe()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Niels Nielsen authored and addaleax committed Oct 18, 2016
1 parent 431638d commit b41cf22
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/parallel/test-stream-pipe-unpipe-streams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'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(() => {}));

// 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);

0 comments on commit b41cf22

Please sign in to comment.