Skip to content

test: bound the HTTP-date Retry-After delay by the call's own clock window - #157

Merged
lesnik512 merged 1 commit into
mainfrom
test/retry-after-date-flake
Oct 4, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
test/retry-after-date-flake

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Fixes a flaky test: test_retry_after_http_date_overrides_backoff failed on #156's floors (3.11) job with assert 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. With frac(now) = 0.9997, truncation alone leaves 2.0003, and 0.6 ms of execution then fell below 2.0. A cold first client.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 records before and after around client.get, aligns the date to a whole second, and asserts future - 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.9997 the old construction gives 2.0003 before elapsed time. The new test passed 30 of 30 consecutive runs locally. just lint-ci passes, and just test-ci passes 1001 tests at 100% coverage.

@lesnik512
lesnik512 merged commit da7ee99 into main Oct 4, 2026
13 checks passed
@lesnik512
lesnik512 deleted the test/retry-after-date-flake branch October 4, 2026 08:25
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