Repository: nodejs/node
Pull request: 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.

This failed 11 PRs out of the last 100 CI runs in the latest reliability report.

Refs: https://github.com/nodejs/reliability/blob/main/reports/2025-10-15.md

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: test/sequential/test-perf-hooks.js
patch: @@ -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.