Files
node/test/parallel/test-bench-clock-precision.js
RafaelGSS cd18965041 lib: set exit code on failed node:bench run()
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/66534
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-10-07 15:39:57 -03:00

26 lines
788 B
JavaScript

// Flags: --experimental-bench --no-warnings
'use strict';
const common = require('../common');
const assert = require('assert');
const originalHrtimeBigint = process.hrtime.bigint;
process.hrtime.bigint = () => 1n;
const { bench, run } = require('node:bench');
process.hrtime.bigint = originalHrtimeBigint;
const completion = bench('zero duration', { samples: 1 }, (b) => {
b.start();
b.end(1);
});
(async () => {
await run().toArray();
const result = await completion;
assert.strictEqual(result.error.code, 'ERR_INVALID_STATE');
assert.match(result.error.message, /insufficient clock precision/);
// The failed run sets the exit code; reset it so the test itself passes.
assert.strictEqual(process.exitCode, 1);
process.exitCode = 0;
})().then(common.mustCall());