From a603d7f8e50aa91db5cb05cd1eda45bb0ecc49ad Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 7 Sep 2026 10:45:23 +0200 Subject: [PATCH 1/3] test: fix flaky test-bench-stream testDeliveryDoesNotConsumeTimeout gave the benchmark a 20ms timeout while stalling the consumer for 50ms. Only delivery time is credited back to the deadline, so the 32 samples still had to run within 20ms, which is about a 10x margin on an idle machine and not enough on a loaded CI runner. Scale the timeout and the stall together so the benchmark's own work gets 500ms of headroom while the consumer still stalls for longer than the timeout. Signed-off-by: Matteo Collina --- test/parallel/test-bench-stream.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-bench-stream.js b/test/parallel/test-bench-stream.js index 9a9eff7b2369..8681b85aab83 100644 --- a/test/parallel/test-bench-stream.js +++ b/test/parallel/test-bench-stream.js @@ -151,15 +151,21 @@ async function testCancellationCompletesBenchmarks() { async function testDeliveryDoesNotConsumeTimeout() { const runner = createRunner({ yieldBetweenSamples: false }); + // The timeout only has to cover the benchmark's own work, which is 32 samples + // that do nothing but record a fixed value. Keep it generous so that a loaded + // machine cannot exhaust it on its own, and keep the consumer stalled for + // longer than the timeout so that the benchmark can only complete when the + // time spent delivering records is excluded from the timeout. + const timeout = common.platformTimeout(500); const completion = runner.bench('slow consumer', { samples: 32, - timeout: common.platformTimeout(20), + timeout, }, recordSample); const stream = runner.run(); const iterator = stream[Symbol.asyncIterator](); await iterator.next(); - await setTimeout(common.platformTimeout(50)); + await setTimeout(timeout * 2); for (;;) { const next = await iterator.next(); if (next.done) break; From bbf8d8d114abfe98d4a1d0003160e61663e5d157 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Mon, 7 Sep 2026 14:33:03 +0200 Subject: [PATCH 2/3] Update test-bench-stream.js Co-authored-by: Antoine du Hamel --- test/parallel/test-bench-stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-bench-stream.js b/test/parallel/test-bench-stream.js index 8681b85aab83..2184635b3989 100644 --- a/test/parallel/test-bench-stream.js +++ b/test/parallel/test-bench-stream.js @@ -165,7 +165,7 @@ async function testDeliveryDoesNotConsumeTimeout() { const iterator = stream[Symbol.asyncIterator](); await iterator.next(); - await setTimeout(timeout * 2); + await setImmediate(); for (;;) { const next = await iterator.next(); if (next.done) break; From 0142cae86fa809faad6668bfa1c24c889b3652e0 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 7 Sep 2026 14:53:03 +0200 Subject: [PATCH 3/3] squash! fix lint --- test/parallel/test-bench-stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-bench-stream.js b/test/parallel/test-bench-stream.js index 2184635b3989..115364c7db5e 100644 --- a/test/parallel/test-bench-stream.js +++ b/test/parallel/test-bench-stream.js @@ -4,7 +4,7 @@ const common = require('../common'); const assert = require('assert'); const { createRunner } = require('node:bench'); -const { setImmediate, setTimeout } = require('timers/promises'); +const { setImmediate } = require('timers/promises'); function recordSample(b) { b.record({