test: fix flaky retry-after ordering assertion in ratelimit tests - #936
Merged
xperimental merged 1 commit intoSep 28, 2026
Merged
Conversation
xperimental
reviewed
Sep 25, 2026
xperimental
left a comment
Contributor
There was a problem hiding this comment.
Sorry for the delay ... I tried to find out why the test code used parallel requests in the first place, but I was not able to. Running the commit where the tests were originally added with a lot of parallelism also yielded some failures, so I'm assuming that it was always flaky. I still have not found out why it was using parallel requests though.
Left a few comments.
IshwarKanse
added a commit
to IshwarKanse/api
that referenced
this pull request
Sep 28, 2026
Address review comments from @xperimental on PR observatorium#936: - Since requests are no longer sent concurrently, accumulate gotOKs/gotTooManyRequests/gotHeaders directly in the loop instead of writing to an intermediate slice and iterating again. - Use the range-over-int form (for range reqNum) instead of a C-style counting loop. - Check the error from res.Body.Close() and fail the test on it, consistent with how the Get error is handled.
IshwarKanse
force-pushed
the
fix-flaky-retry-after-test
branch
from
September 28, 2026 02:05
7e48b66 to
03fb62d
Compare
launchTestRequests fired requests from goroutines staggered only by a 1ms sleep, then stored each result by launch index. The shared rate limiter assigns Retry-After values in server-arrival order under a mutex, so a 1ms stagger doesn't guarantee arrival order matches launch order under CI load. This let TestWithSharedRateLimiter/one_rate_limiter_with_additional_retry_after_logic flake when requests arrived out of order (observed on CircleCI, ci/circleci: test, build 13935, on PR observatorium#934). Since the affected subtests assert a strict, deterministic Retry-After progression, true concurrency isn't needed: send each request synchronously, waiting for its response before firing the next, and accumulate results directly instead of through an intermediate slice.
IshwarKanse
force-pushed
the
fix-flaky-retry-after-test
branch
from
September 28, 2026 03:00
03fb62d to
5c6d995
Compare
xperimental
approved these changes
Sep 28, 2026
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
launchTestRequestsinratelimit/http_test.gofired requests from goroutines staggered only by a 1mstime.Sleep, then stored each result by launch index. The shared rate limiter'sgetAndSetNextRetryAfterValue(ratelimit/http.go) doubles theRetry-Aftervalue deterministically in server-arrival order under a mutex, not launch order, so a 1ms stagger doesn't guarantee the two stay in sync under CI load.TestWithSharedRateLimiter/one_rate_limiter_with_additional_retry_after_logicto occasionally fail with something likeunexpected Retry-After header values: wanted [ 1 4 8 16], got [ 1 4 16 8]. Observed on CircleCI (ci/circleci: test, build 13935) on fix: preserve empty traces/resourceSpans arrays in RBAC-filtered trace responses #934, unrelated to that PR's actual changes.Retry-Afterprogression, true concurrency isn't needed to exercise that behavior.launchTestRequestsnow sends each request synchronously and waits for its response before firing the next one, so launch order and server-arrival order can never diverge.Test plan
go build ./ratelimit/...go vet ./ratelimit/...gofmt -l ratelimit/http_test.go(no output)go test ./ratelimit/... -run TestWithSharedRateLimiter -count=20 -race— all passgo test ./ratelimit/... -count=10 -race— full package, all pass🤖 Generated with Claude Code