Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
12 changes: 12 additions & 0 deletions test/unit/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
List,
MongoDBCollectionNamespace,
MongoDBNamespace,
now,
shuffle
} from '../../src/utils';
import { sleep } from '../tools/utils';
Expand Down Expand Up @@ -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);
});
});
});