Repository navigation
Check the throttling test against elapsed time, not how many calls slept - #818
Merged
Merged
Conversation
The test counted calls that slept for a refill and wanted at least 20. On a loaded runner refills land between slow calls, so fewer need to sleep, and it failed three times in a day on unrelated pull requests. It now checks that the run took as long as the refill rate requires, which holds on any machine, and that at least one call slept.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approved
The revised assertion matches the token-bucket configuration and avoids the reported scheduler-dependent flakiness.
Review effort: Balanced
Findings: None
What changed in this PR
Replaces a flaky sleeper-count assertion with an elapsed-time check for default rate limiting.
Changes:
- Records elapsed time for barriered invocations.
- Verifies 30 uncovered calls require approximately three seconds of refill time.
- Retains checks that the wait path and bulkhead limits are exercised.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
internal/resilience/gate_test.go |
Measures throttling by elapsed refill time instead of scheduler-sensitive sleep counts. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 1 file
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
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.
Problem
TestGateQueuesTenParallelWorkersThroughTheDefaultsfailed three times on 1 October, on three unrelated PRs (#815, #816, #791), and passed each time on a rerun. It counted how many of the 30 calls the starting token bucket can't cover slept for a refill, and wanted at least 20. On a loaded runner, under the race detector, the calls themselves are slow, refills land between them, and a call that finds a token waiting is served without sleeping. That's correct limiter behaviour, so the count was measuring the runner (it came in at 7, 17 and 19).Solution
The test now checks the throttling by time: 80 calls against a 50-token bucket refilling at 10 a second can't finish in under 3 seconds on any machine, and a slow one only takes longer. It asserts the run took at least 90% of that, and that at least one call slept (so the wait path and its counter are exercised). The bulkhead and success assertions are unchanged.
To check it still catches a real bug, I broke the limiter to refill five times too fast: the test fails with "30 calls past the starting bucket cannot finish before 30 tokens refill (3s); it took 623ms". It passed 40 runs under the race detector with four copies competing for the CPU. I couldn't reproduce the original flake locally (the old version passed those runs too), so the CI failures above are the evidence for it.
Summary by cubic
Fixes the flaky
TestGateQueesTenParallelWorkersThroughTheDefaultstest, which throttling assertions counted calls that slept for a refill and required at least 20 of 30. On a loaded runner, refills land between slow calls so fewer calls need to sleep, and the test failed three times in a day on unrelated PRs.The test now measures throttling by elapsed time instead. It asserts the run takes at least 90% of the time 30 tokens take to refill (3 seconds at 10 per second) — true on any machine, slower ones only take longer — and that at least one call slept, so the wait path is exercised.
Written for commit 5b9f671. Summary will update on new commits.