Fix exceeded() to fall back to configured interval when Retry-After is missing#28
Merged
Sammyjo20 merged 3 commits intosaloonphp:v2from Mar 25, 2026
Conversation
…igured interval When `exceeded()` is called without a `releaseInSeconds` value (e.g. when a 429 response has no Retry-After header), the expiry timestamp was not set explicitly. This caused it to be lazily calculated from "now" on each call to `getExpiryTimestamp()`, which can drift and lead to inconsistent state. Now `exceeded()` falls back to the limit's configured `releaseInSeconds` when no explicit value is provided, ensuring the expiry timestamp is always set deterministically at the moment the limit is exceeded.
JonPurvis
approved these changes
Mar 23, 2026
Contributor
JonPurvis
left a comment
There was a problem hiding this comment.
👍 Thanks for this @evan-burrell
Add a `toLookLike` custom expectation that tolerates ±1 second drift on timestamps, preventing flaky failures when a second boundary is crossed between capturing the expected time and executing the request.
Contributor
Author
|
@Sammyjo20 Just added an extended expectation for clock based tests that might be flaky |
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
When
Limit::exceeded()is called without areleaseInSecondsvalue (e.g. when a 429 response has noRetry-Afterheader), theexpiryTimestampwas not set explicitly. This caused it to be lazily recalculated from "now" on each call togetExpiryTimestamp(), which can drift and produce inconsistent state depending on when it's accessed.This change makes
exceeded()fall back to the limit's configuredreleaseInSecondsinterval when no explicit value is provided, ensuring the expiry timestamp is always set deterministically at the moment the limit is exceeded.Before
After
Changes
src/Limit.php: Inexceeded(), fall back to$this->releaseInSecondswhen$releaseInSecondsis nulltests/Unit/LimitTest.php: Added 3 tests covering the fallback behavior for regular limits, explicit values, and custom limiterstests/Pest.php: AddedtoLookLikecustom Pest expectation that tolerates ±1 second timestamp drifttests/Feature/HasRateLimitsTest.php: Replaced exact timestamp assertions withtoLookLiketo fix flaky CI failures on slow runnersTest plan
releaseInSecondsis nullreleaseInSecondsstill takes precedenceLimit::custom()defaults to 60s fallbacktoLookLikeexpectation