Skip to content

Commit 990aefd

Browse files
jasnellnodejs-github-bot
authored andcommitted
lib: fix stream loading bug in node:bench
Not all of the stream APIs are correctly loaded until the `node:stream` module is loaded. Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: #66114 Fixes: #41641 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent a2dedcc commit 990aefd

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎lib/internal/bench_runner/benchmarks_stream.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const {
2424
SetPrototypeValues,
2525
Symbol,
2626
} = primordials;
27-
const Readable = require('internal/streams/readable');
27+
const { Readable } = require('stream');
2828
const { deserializeError, serializeError } = require('internal/error_serdes');
2929
const {
3030
codes: {

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
const common = require('../common');
5+
const { spawnSyncAndAssert } = require('../common/child_process');
56
const assert = require('assert');
67
const { createRunner } = require('node:bench');
78
const { setImmediate } = require('timers/promises');
@@ -375,6 +376,32 @@ async function testRecordOwnership() {
375376
assert.strictEqual(streamSummary.counts.total, 7);
376377
}
377378

379+
function testOperatorsWithoutStreamModule() {
380+
// Readable operators such as map() and toArray() are attached when
381+
// node:stream is loaded. node:assert and ../common load node:stream, so
382+
// check the operators in a child process that loads only node:bench.
383+
const script = `
384+
const { createRunner } = require('node:bench');
385+
const runner = createRunner({ yieldBetweenSamples: false });
386+
runner.bench('operators', { samples: 1 }, (b) => {
387+
b.record({ operations: 1, duration_ns: 1n });
388+
});
389+
runner.run()
390+
.map((record) => record.type)
391+
.toArray()
392+
.then((types) => console.log(types.includes('bench:complete')));
393+
`;
394+
spawnSyncAndAssert(process.execPath, [
395+
'--experimental-bench',
396+
'--no-warnings',
397+
'-e',
398+
script,
399+
], {
400+
stdout: 'true',
401+
trim: true,
402+
});
403+
}
404+
378405
(async () => {
379406
await testReadableBackpressure();
380407
await testPlanBackpressure();
@@ -385,4 +412,5 @@ async function testRecordOwnership() {
385412
await testReportingFailureSettlesBenchmarks();
386413
await testSummaryListenerFailure();
387414
await testRecordOwnership();
415+
testOperatorsWithoutStreamModule();
388416
})().then(common.mustCall());

0 commit comments

Comments
 (0)