Skip to content

Commit 23a05a6

Browse files
mcollinajasnell
authored andcommitted
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> PR-URL: #65874 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3202f63 commit 23a05a6

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

test/parallel/test-bench-stream.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const common = require('../common');
55
const assert = require('assert');
66
const { createRunner } = require('node:bench');
7-
const { setImmediate, setTimeout } = require('timers/promises');
7+
const { setImmediate } = require('timers/promises');
88

99
function recordSample(b) {
1010
b.record({
@@ -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 setImmediate();
163169
for (;;) {
164170
const next = await iterator.next();
165171
if (next.done) break;

0 commit comments

Comments
 (0)