From 69c7752aa32faa452db8de9dcdaceffe5779be79 Mon Sep 17 00:00:00 2001 From: Pavel Horal Date: Tue, 11 Oct 2022 10:38:05 +0200 Subject: [PATCH] test: add failing test for duplex backpressure --- test/parallel/test-stream-duplex-from.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-stream-duplex-from.js b/test/parallel/test-stream-duplex-from.js index 0d97938a321ae4..7d26d59dc504b6 100644 --- a/test/parallel/test-stream-duplex-from.js +++ b/test/parallel/test-stream-duplex-from.js @@ -2,7 +2,7 @@ const common = require('../common'); const assert = require('assert'); -const { Duplex, Readable, Writable, pipeline } = require('stream'); +const { Duplex, Readable, Writable, pipeline, PassThrough, Transform } = require('stream'); const { Blob } = require('buffer'); { @@ -148,6 +148,27 @@ const { Blob } = require('buffer'); ); } +// https://github.com/nodejs/node/issues/44925 +{ + const through = new PassThrough({ objectMode: true }); + const stream = Readable.from(['foo', 'bar'], { objectMode: true }) + .pipe(Duplex.from({ + writable: through, + readable: through + })) + .pipe(new Transform({ + objectMode: true, + highWaterMark: 1, // Force backpressure to occur + transform(chunk, encoding, callback) { + callback(null, chunk); + } + })); + stream.toArray() + .then(common.mustCall((values) => { + assert.strictEqual(values.join(' '), 'foo bar'); + })); +} + // Ensure that isDuplexNodeStream was called { const duplex = new Duplex();