fix: eliminate flaky TestHedgeMarket_startAndHedge race condition#2441
Merged
fix: eliminate flaky TestHedgeMarket_startAndHedge race condition#2441
Conversation
…edge interval The test was flaky because the 10ms hedge ticker could race with the positionDeltaC channel in the hedgeWorker select loop. When Go's runtime randomly picked the ticker case while a channel delta was also ready, the accumulated uncovered position could cause a SubmitOrder call with an unexpected quantity, failing the mock expectation. Fix: use a 1-hour hedge interval so the ticker never fires during the test. The test drives all hedging through positionDeltaC and synchronizes via hedgedC, so it does not need the ticker at all. Closes c9s#2231
c9s
approved these changes
Mar 31, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2441 +/- ##
==========================================
+ Coverage 19.74% 19.81% +0.07%
==========================================
Files 1091 1090 -1
Lines 74014 73700 -314
==========================================
- Hits 14614 14604 -10
+ Misses 58066 57764 -302
+ Partials 1334 1332 -2 see 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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
TestHedgeMarket_startAndHedgewas flaky in CIpositionDeltaCchannel deltas, causing accumulated quantities to mismatch gomock expectationspositionDeltaC+hedgedCsynchronizationChanges
pkg/strategy/xmaker/hedgemarket_test.go— 5 lines added, 1 removedTest plan
go test ./pkg/strategy/xmaker/ -run TestHedgeMarket_startAndHedge -count=100passes consistently