Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions test/parallel/test-bench-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 setImmediate();
for (;;) {
const next = await iterator.next();
if (next.done) break;
Expand Down
Loading