test: bound the HTTP-date Retry-After delay by the call's own clock window - #157
Merged
Merged
Conversation
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.
Fixes a flaky test:
test_retry_after_http_date_overrides_backofffailed on #156'sfloors (3.11)job withassert 2.0 <= 1.999698.Cause
The test built a date "now + 3s" and asserted a delay of 2 to 4 seconds. An HTTP-date has whole-second precision, so formatting drops the sub-second part and the delay comes out as
3 - frac(now) - elapsed. Withfrac(now) = 0.9997, truncation alone leaves 2.0003, and 0.6 ms of execution then fell below 2.0. A cold firstclient.get(lazy imports) can also stall for well over a second, which breaks any fixed tolerance.Fix
The delay retry sleeps is exactly
parsed - datetime.now(), taken at some instant during the call. So the test now recordsbeforeandafteraroundclient.get, aligns the date to a whole second, and assertsfuture - after <= delay <= future - before. That holds however long the call takes, with no tolerance constant. No production code changes.Verification
The failing case reproduces off-CI: at
now = …:00.9997the old construction gives 2.0003 before elapsed time. The new test passed 30 of 30 consecutive runs locally.just lint-cipasses, andjust test-cipasses 1001 tests at 100% coverage.