Skip to content

Fix rate-limit test exceeding Jest's 10s timeout via a real 60s sleep - #4

Merged
urbantech merged 1 commit into
mainfrom
fix/rate-limit-test-fake-timers-9368
Oct 28, 2026
Merged

urbantech merged 1 commit into
mainfrom
fix/rate-limit-test-fake-timers-9368

Conversation

@urbantech

Copy link
Copy Markdown
Contributor

Summary

This is the same fix merged to `core` as part of core#9368 (the x402 SDK port). `v3.2.0`'s own release (triggered by the tag in PR #3) failed CI's gating `npm run test` step on this exact test and never published — this PR fixes it so the release can be re-cut.

`client.ts`'s retry loop honors a real `retry-after` value with a genuine `setTimeout()` before retrying. The "should handle rate limit errors" test mocked every request attempt to reject with `retry-after: '60'` and never used fake timers, so it genuinely slept close to 60 real seconds before Jest's 10s default timeout killed it. Deterministic, not flaky.

Fix

Wraps this one test in `jest.useFakeTimers()` / `jest.runAllTimersAsync()`. No other test in this file needed it.

Test plan — real output

```
npx jest
```
```
Test Suites: 7 passed, 7 total
Tests: 211 passed, 211 total
Time: 45.592 s
```

Refs AINative-Studio/core#9368

client.ts's retry loop honors a real WWW-Authenticate/retry-after value
with a genuine setTimeout() before retrying. This test mocked every
request attempt to reject with retry-after: '60' and never used fake
timers, so it genuinely slept close to 60 real seconds before Jest's
10s default timeout killed it -- deterministically, not flaky, in every
environment (reproduced identically on core's copy, a clean local
checkout of this repo, and the v3.2.0 release's CI run, which failed
for exactly this reason and never published).

Fix: wrap this one test in jest.useFakeTimers() / runAllTimersAsync()
so the retry sleep resolves instantly instead of waiting in real time.
No other test in this file needed the same fix -- it's the only one
exercising the retry-after path with a reject-every-attempt mock.

Found while re-publishing v3.2.0 after the x402 PR's own release
(the first v3.2.0 tag) failed its gating test step for this exact
reason.

Refs AINative-Studio/core#9368
@urbantech
urbantech merged commit 3d8ca5f into main Oct 28, 2026
@urbantech
urbantech deleted the fix/rate-limit-test-fake-timers-9368 branch October 28, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant