From ba86a88ec03cfe77de3a763a3074132cbce724d1 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Sun, 17 May 2026 13:42:41 -0700 Subject: [PATCH 1/2] test: make Brotli 16GB test wait for backpressure Wait for the Brotli decoder to fill its readable buffer before checking that decompression stops at the high water mark. This avoids racing the fixed timeout against libuv worker-pool scheduling. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 --- test/parallel/test-zlib-brotli-16GB.js | 33 +++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-zlib-brotli-16GB.js b/test/parallel/test-zlib-brotli-16GB.js index 7bd5a137f908fd..ace8bfaf0a09cb 100644 --- a/test/parallel/test-zlib-brotli-16GB.js +++ b/test/parallel/test-zlib-brotli-16GB.js @@ -15,9 +15,30 @@ const buf = Buffer.from(content, 'hex'); const decoder = createBrotliDecompress(); decoder.end(buf); -// We need to wait to verify that the libuv thread pool had time -// to process the data and the buffer is not empty. -setTimeout(common.mustCall(() => { - // There is only one chunk in the buffer - assert.strictEqual(decoder._readableState.buffer.length, getDefaultHighWaterMark() / (16 * 1024)); -}), common.platformTimeout(500)); +const expectedBufferedChunks = getDefaultHighWaterMark() / (16 * 1024); + +const timeout = setTimeout(() => { + assert.fail(`Timed out waiting for Brotli output. ` + + `Buffered ${decoder._readableState.buffer.length} chunks.`); +}, common.platformTimeout(5000)); + +function waitForBackpressure() { + const bufferedChunks = decoder._readableState.buffer.length; + + assert.ok(bufferedChunks <= expectedBufferedChunks); + + if (bufferedChunks < expectedBufferedChunks) { + setImmediate(waitForBackpressure); + return; + } + + clearTimeout(timeout); + + // Verify that decompression stopped once the readable buffer filled up. + setTimeout(common.mustCall(() => { + assert.strictEqual(decoder._readableState.buffer.length, + expectedBufferedChunks); + }), common.platformTimeout(500)); +} + +waitForBackpressure(); From cf75868c2ac5782075fb6a159413b292425e74ed Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Wed, 27 May 2026 22:06:06 -0700 Subject: [PATCH 2/2] test: remove arbitrary Brotli backpressure timeout --- test/parallel/test-zlib-brotli-16GB.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test/parallel/test-zlib-brotli-16GB.js b/test/parallel/test-zlib-brotli-16GB.js index ace8bfaf0a09cb..b575f29afea4c3 100644 --- a/test/parallel/test-zlib-brotli-16GB.js +++ b/test/parallel/test-zlib-brotli-16GB.js @@ -17,11 +17,6 @@ decoder.end(buf); const expectedBufferedChunks = getDefaultHighWaterMark() / (16 * 1024); -const timeout = setTimeout(() => { - assert.fail(`Timed out waiting for Brotli output. ` + - `Buffered ${decoder._readableState.buffer.length} chunks.`); -}, common.platformTimeout(5000)); - function waitForBackpressure() { const bufferedChunks = decoder._readableState.buffer.length; @@ -32,8 +27,6 @@ function waitForBackpressure() { return; } - clearTimeout(timeout); - // Verify that decompression stopped once the readable buffer filled up. setTimeout(common.mustCall(() => { assert.strictEqual(decoder._readableState.buffer.length,