Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7853a7f

Browse filesBrowse files
committed
test: add test for stream unpipe with 'data' listeners
PR-URL: #18516 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent e33b9fa commit 7853a7f
Copy full SHA for 7853a7f

File tree

Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Open diff view settings
Collapse file
+29Lines changed: 29 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.