mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: fix incorrect calculation in test-perf-hooks.js
After https://redirect.github.com/nodejs/node/pull/46588, Date.now() - performance.timeOrigin and process.uptime() are no longer similar - the former measures uptime from process initilaization, while the latter measures uptime from the main context initialization. Account for the differences in the test. PR-URL: https://github.com/nodejs/node/pull/60271 Refs: https://github.com/nodejs/reliability/blob/main/reports/2025-10-15.md Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
This commit is contained in:
@@ -28,15 +28,10 @@ const epsilon = 50;
|
||||
{
|
||||
const uptime1 = Date.now() - performance.timeOrigin;
|
||||
const uptime2 = performance.now();
|
||||
const uptime3 = process.uptime() * 1000;
|
||||
assert(Math.abs(uptime1 - uptime2) < epsilon,
|
||||
`Date.now() - performance.timeOrigin (${uptime1}) - ` +
|
||||
`performance.now() (${uptime2}) = ` +
|
||||
`${uptime1 - uptime2} >= +- ${epsilon}`);
|
||||
assert(Math.abs(uptime1 - uptime3) < epsilon,
|
||||
`Date.now() - performance.timeOrigin (${uptime1}) - ` +
|
||||
`process.uptime() * 1000 (${uptime3}) = ` +
|
||||
`${uptime1 - uptime3} >= +- ${epsilon}`);
|
||||
}
|
||||
|
||||
assert.strictEqual(performance.nodeTiming.name, 'node');
|
||||
@@ -58,8 +53,8 @@ function checkNodeTiming(timing) {
|
||||
// performance.now() i.e. measures Node.js instance up time.
|
||||
assert.strictEqual(typeof timing.duration, 'number');
|
||||
assert(timing.duration > 0, `timing.duration ${timing.duration} <= 0`);
|
||||
assert(delta < 10,
|
||||
`now (${now}) - timing.duration (${timing.duration}) = ${delta} >= ${10}`);
|
||||
assert(delta < epsilon,
|
||||
`now (${now}) - timing.duration (${timing.duration}) = ${delta} >= ${epsilon}`);
|
||||
|
||||
// Check that the following fields do not change.
|
||||
assert.strictEqual(timing.startTime, initialTiming.startTime);
|
||||
@@ -93,6 +88,18 @@ checkNodeTiming(initialTiming);
|
||||
assert(nodeStart < testStartTime,
|
||||
`nodeStart ${nodeStart} >= ${testStartTime}`);
|
||||
|
||||
{
|
||||
// Due to https://github.com/nodejs/node/pull/46588,
|
||||
// The difference between process.uptime() and (Date.now() - performance.timeOrigin)
|
||||
// is roughly performance.nodeTiming.nodeStart
|
||||
const uptime1 = Date.now() - performance.timeOrigin; // now - process start time
|
||||
const uptime3 = process.uptime() * 1000; // now - node start time
|
||||
assert(Math.abs(uptime1 - uptime3 - nodeStart) < epsilon,
|
||||
`Date.now() - performance.timeOrigin (${uptime1}) - ` +
|
||||
`process.uptime() * 1000 (${uptime3}) = ` +
|
||||
`${uptime1 - uptime3} >= +- ${epsilon}`);
|
||||
}
|
||||
|
||||
assert.strictEqual(typeof v8Start, 'number');
|
||||
assert(v8Start > 0, `v8Start ${v8Start} <= 0`);
|
||||
// V8 starts after the process starts.
|
||||
|
||||
Reference in New Issue
Block a user