Skip to content

Commit c92e5cb

Browse files
committed
test(billing): use 1 ms waits in the reporting usage cache expiry test
1 parent 08c9641 commit c92e5cb

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎apps/sim/lib/billing/core/reporting-usage-cache.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ describe('readSoftGateUsageCost on a reporting window', () => {
5858
mockGetBillingPeriodUsageCost.mockResolvedValueOnce(10).mockResolvedValueOnce(25)
5959

6060
await expect(readSoftGateUsageCost(org, REPORTING)).resolves.toBe(10)
61-
/** The cache re-reads its clock only after `ttlResolution` (1 ms) of real time. */
61+
/**
62+
* The cache refreshes its clock on a 1 ms `ttlResolution` timer scheduled when it last read
63+
* the time, so it always fires before a 1 ms sleep queued afterwards.
64+
*/
6265
clock.mockReturnValue(start + REPORTING_USAGE_CACHE_TTL_MS - 1)
63-
await sleep(2)
66+
await sleep(1)
6467
await expect(readSoftGateUsageCost(org, REPORTING)).resolves.toBe(10)
6568
clock.mockReturnValue(start + REPORTING_USAGE_CACHE_TTL_MS + 1)
66-
await sleep(2)
69+
await sleep(1)
6770
await expect(readSoftGateUsageCost(org, REPORTING)).resolves.toBe(25)
6871
expect(mockGetBillingPeriodUsageCost).toHaveBeenCalledTimes(2)
6972
})

0 commit comments

Comments
 (0)