File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -436,8 +436,7 @@ export function makeStateMachine(stateTable: StateTable): StateTransitionFunctio
436436
437437/** @internal */
438438export 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 */
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {
2121 List ,
2222 MongoDBCollectionNamespace ,
2323 MongoDBNamespace ,
24+ now ,
2425 shuffle
2526} from '../../src/utils' ;
2627import { 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} ) ;
You can’t perform that action at this time.
0 commit comments