Skip to content

Commit 7853a7f

Browse files
committed
test: add test for stream unpipe with 'data' listeners
PR-URL: #18516 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent e33b9fa commit 7853a7f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { Readable, Writable } = require('stream');
4+
5+
// Tests that calling .unpipe() un-blocks a stream that is paused because
6+
// it is waiting on the writable side to finish a write().
7+
8+
const rs = new Readable({
9+
highWaterMark: 1,
10+
// That this gets called at least 20 times is the real test here.
11+
read: common.mustCallAtLeast(() => rs.push('foo'), 20)
12+
});
13+
14+
const ws = new Writable({
15+
highWaterMark: 1,
16+
write: common.mustCall(() => {
17+
// Ignore the callback, this write() simply never finishes.
18+
setImmediate(() => rs.unpipe(ws));
19+
})
20+
});
21+
22+
let chunks = 0;
23+
rs.on('data', common.mustCallAtLeast(() => {
24+
chunks++;
25+
if (chunks >= 20)
26+
rs.pause(); // Finish this test.
27+
}));
28+
29+
rs.pipe(ws);

0 commit comments

Comments
 (0)