Skip to content

Commit c31e63d

Browse files
committed
fix(NODE-7307): Replace node:process.hrtime() with performance.now()
1 parent f433e11 commit c31e63d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ export function makeStateMachine(stateTable: StateTable): StateTransitionFunctio
436436

437437
/** @internal */
438438
export function now(): number {
439-
const hrtime = process.hrtime();
440-
return Math.floor(hrtime[0] * 1000 + hrtime[1] / 1000000);
439+
return Math.floor(performance.now());
441440
}
442441

443442
/** @internal */

test/unit/utils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
List,
2222
MongoDBCollectionNamespace,
2323
MongoDBNamespace,
24+
now,
2425
shuffle
2526
} from '../../src/utils';
2627
import { sleep } from '../tools/utils';
@@ -1285,4 +1286,15 @@ describe('driver utils', function () {
12851286
});
12861287
});
12871288
});
1289+
1290+
describe('now()', () => {
1291+
it('difference between two calls is close to sleep time', async () => {
1292+
const time1 = now();
1293+
await sleep(10);
1294+
const time2 = now();
1295+
const diff = time2 - time1;
1296+
expect(diff).to.be.gte(5);
1297+
expect(diff).to.be.lte(15);
1298+
});
1299+
});
12881300
});

0 commit comments

Comments
 (0)