Skip to content

Commit a603d7f

Browse files
committed
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 <hello@matteocollina.com>
1 parent 6f38736 commit a603d7f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎test/parallel/test-bench-stream.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,21 @@ async function testCancellationCompletesBenchmarks() {
151151

152152
async function testDeliveryDoesNotConsumeTimeout() {
153153
const runner = createRunner({ yieldBetweenSamples: false });
154+
// The timeout only has to cover the benchmark's own work, which is 32 samples
155+
// that do nothing but record a fixed value. Keep it generous so that a loaded
156+
// machine cannot exhaust it on its own, and keep the consumer stalled for
157+
// longer than the timeout so that the benchmark can only complete when the
158+
// time spent delivering records is excluded from the timeout.
159+
const timeout = common.platformTimeout(500);
154160
const completion = runner.bench('slow consumer', {
155161
samples: 32,
156-
timeout: common.platformTimeout(20),
162+
timeout,
157163
}, recordSample);
158164
const stream = runner.run();
159165
const iterator = stream[Symbol.asyncIterator]();
160166

161167
await iterator.next();
162-
await setTimeout(common.platformTimeout(50));
168+
await setTimeout(timeout * 2);
163169
for (;;) {
164170
const next = await iterator.next();
165171
if (next.done) break;

0 commit comments

Comments
 (0)