Skip to content

Commit bca87d9

Browse files
Stabilize the outdated rate-limit cache test
The test advanced the clock relative to the real system time while the rate-limit occurrences were recorded against it, so the occurrences could land exactly on the inclusive window start and stay throttled. Freeze the clock and advance strictly past the window instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6e186a3 commit bca87d9

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎packages/cli-kit/src/private/node/conf-store.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getCachedPartnerAccountStatus,
1414
setCachedPartnerAccountStatus,
1515
runWithRateLimit,
16+
timeIntervalToMilliseconds,
1617
} from './conf-store.js'
1718
import {isLocalEnvironment} from './context/service.js'
1819
import {LocalStorage} from '../../public/node/local-storage.js'
@@ -548,6 +549,7 @@ describe('runWithRateLimit', () => {
548549
test('runs the task as usual when the cache is populated but outdated', async () => {
549550
await inTemporaryDirectory(async (cwd) => {
550551
// Given
552+
vi.useFakeTimers()
551553
const config = new LocalStorage<any>({cwd})
552554
for (let i = 0; i < limit; i++) {
553555
// eslint-disable-next-line no-await-in-loop
@@ -564,7 +566,8 @@ describe('runWithRateLimit', () => {
564566

565567
// When
566568
let taskRan = false
567-
vi.setSystemTime(vi.getRealSystemTime() + 1000)
569+
// The rate-limit window is inclusive of its start, so advance strictly past it.
570+
vi.advanceTimersByTime(timeIntervalToMilliseconds(timeout) + 1)
568571
const got = await runWithRateLimit(
569572
{
570573
key,

0 commit comments

Comments
 (0)