Repository navigation
Fix rate-limit test exceeding Jest's 10s timeout via a real 60s sleep - #4
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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