From c31e63df80c41a4845cc3f8793621ab6850c6c3a Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Mon, 1 Dec 2025 14:21:26 -0800 Subject: [PATCH 1/2] fix(NODE-7307): Replace node:process.hrtime() with performance.now() --- src/utils.ts | 3 +-- test/unit/utils.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 49aa15ccea4..e6638ed27cf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -436,8 +436,7 @@ export function makeStateMachine(stateTable: StateTable): StateTransitionFunctio /** @internal */ export function now(): number { - const hrtime = process.hrtime(); - return Math.floor(hrtime[0] * 1000 + hrtime[1] / 1000000); + return Math.floor(performance.now()); } /** @internal */ diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index dc393fe0990..c2f87afb5a7 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -21,6 +21,7 @@ import { List, MongoDBCollectionNamespace, MongoDBNamespace, + now, shuffle } from '../../src/utils'; import { sleep } from '../tools/utils'; @@ -1285,4 +1286,15 @@ describe('driver utils', function () { }); }); }); + + describe('now()', () => { + it('difference between two calls is close to sleep time', async () => { + const time1 = now(); + await sleep(10); + const time2 = now(); + const diff = time2 - time1; + expect(diff).to.be.gte(5); + expect(diff).to.be.lte(15); + }); + }); }); From 36ab7b1f7291df27e7b6b4d941ef1157552ea3ac Mon Sep 17 00:00:00 2001 From: Pavel Safronov Date: Tue, 2 Dec 2025 15:11:22 -0800 Subject: [PATCH 2/2] remove unnecessary test --- test/unit/utils.test.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/unit/utils.test.ts b/test/unit/utils.test.ts index c2f87afb5a7..dc393fe0990 100644 --- a/test/unit/utils.test.ts +++ b/test/unit/utils.test.ts @@ -21,7 +21,6 @@ import { List, MongoDBCollectionNamespace, MongoDBNamespace, - now, shuffle } from '../../src/utils'; import { sleep } from '../tools/utils'; @@ -1286,15 +1285,4 @@ describe('driver utils', function () { }); }); }); - - describe('now()', () => { - it('difference between two calls is close to sleep time', async () => { - const time1 = now(); - await sleep(10); - const time2 = now(); - const diff = time2 - time1; - expect(diff).to.be.gte(5); - expect(diff).to.be.lte(15); - }); - }); });