Initial overview of how the RetryAfter metadata should be set and tested#124478
Draft
asbjornvad wants to merge 2 commits intodotnet:mainfrom
Draft
Initial overview of how the RetryAfter metadata should be set and tested#124478asbjornvad wants to merge 2 commits intodotnet:mainfrom
asbjornvad wants to merge 2 commits intodotnet:mainfrom
Conversation
…ted. This commit solves the issue of wrongly returned RetryAfter value, however only in the FixedWindowRateLimiter. It shows how it should be used tested. The queue is not taken into consideration in this implementation. dotnet#92557
Author
|
@dotnet-policy-service agree |
Contributor
|
Tagging subscribers to this area: @agocke, @VSadov |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix issue #92557 where the FixedWindowRateLimiter incorrectly returns the full window duration as the Retry-After value instead of the remaining time until the next window. The implementation changes the CreateFailedWindowLease method to calculate the remaining time by subtracting the elapsed time from the window duration.
Changes:
- Modified
CreateFailedWindowLeaseto calculate remaining time instead of returning static window multiples - Added a test-injectable function field to control elapsed time behavior for testing
- Updated test assertions to reflect the new expected behavior
- Added a test helper method to manipulate elapsed time in tests
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs | Adds injectable getElapsedTime function field; reimplements CreateFailedWindowLease to calculate remaining window time; comments out original queue-aware implementation |
| src/libraries/System.Threading.RateLimiting/tests/FixedWindowRateLimiterTests.cs | Adds SetElapsedTime helper for testing; updates test expectations; adds calls to set elapsed time to 0 in multiple tests |
...es/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.RateLimiting/tests/FixedWindowRateLimiterTests.cs
Show resolved
Hide resolved
...es/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs
Outdated
Show resolved
Hide resolved
...es/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.RateLimiting/tests/FixedWindowRateLimiterTests.cs
Outdated
Show resolved
Hide resolved
...es/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs
Outdated
Show resolved
Hide resolved
...es/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs
Outdated
Show resolved
Hide resolved
...es/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.RateLimiting/tests/FixedWindowRateLimiterTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Threading.RateLimiting/tests/FixedWindowRateLimiterTests.cs
Outdated
Show resolved
Hide resolved
a64de24 to
4a1af36
Compare
...es/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs
Outdated
Show resolved
Hide resolved
…ideration the CoPilot suggestions. Not all suggestions were valid. Added 2 tests, one to test partially elapsed window and one where the whole window has elapsed, but hasnt been refreshed.
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.
This commit solves the issue of wrongly returned RetryAfter value, however only in the FixedWindowRateLimiter.
It shows how it could be tested.
The queue is not taken into consideration in this implementation.
There are no new tests since this is a draft.
#92557