Repository navigation
test(limiter): observe grant order, not goroutine completion order - #1154
Merged
Merged
Conversation
…1150) TestFastPathDoesNotOvertakeAQueue asserted FIFO by racing two buffered channel sends. Both queued callers released their slot BEFORE reporting, so the second could be granted, released and reported while the first was still reporting. When both reports landed before the test reached its select, Go picked a ready case uniformly at random and the test failed with "FIFO violated" in 0.00s — the limiter having done nothing wrong. Reproduced on the unfixed tree (macOS arm64, GOMAXPROCS=4, -count=500), and pinned to the select: inserting a 20ms pause after held() so both reports are buffered first fails 21/40 runs, i.e. the coin flip. Each queued call now parks in the slot it wins until the test hands it back. Under a cap of 1 that makes at most one call reachable past admission at a time, so the two admissions can never be reported concurrently and the order read is the order granted. The test also pins Running/Queued while the first caller holds the slot, and after both drain. No production behaviour changes. The rewritten test still catches the regressions it was written for: dropping the fast path's queue guard and serving the queue tail instead of its head both fail it 5/5.
Deploying mcpproxy-docs with
|
| Latest commit: |
a2e74f5
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8ce25baa.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-1150-flaky-limiter.mcpproxy-docs.pages.dev |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 33468753754 --repo smart-mcp-proxy/mcpproxy-go
|
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 #1150.
The flake was in the test, not the limiter
TestFastPathDoesNotOvertakeAQueueasserted FIFO ordering by racing two buffered channel sends. Both queued callers released their slot before reporting, so the second could be granted, released, and reported while the first was still reporting. When both reports landed before the test reached itsselect, Go picked a ready case uniformly at random and the test failed with "FIFO violated" — in0.00s, with the limiter having done nothing wrong.That
(0.00s)in the CI logs was the tell: the assertion resolved immediately, so nothing had timed out. It was observing the wrong thing.The fix
Observe grant order instead of goroutine completion order — the property the test actually means to assert. No sleeps, no raised timeouts, no retries, no skip mark; those hide a flake rather than remove it, and leave the next reader unable to tell which happened.
Verification
-count=200): pass-race: passPrior evidence it was flaky on
main, not PR-specific: run 33374513826 (commit1041e4ec, main) and run 33418347015 (a PR not touching the package) both failed identically.Reviewed under three adversarial lenses (correctness / security / regression): clean, no findings.