Skip to content

fix: eliminate flaky TestHedgeMarket_startAndHedge race condition#2441

Merged
c9s merged 1 commit intoc9s:mainfrom
Bortlesboat:fix/flaky-hedgemarket-test
Mar 31, 2026
Merged

fix: eliminate flaky TestHedgeMarket_startAndHedge race condition#2441
c9s merged 1 commit intoc9s:mainfrom
Bortlesboat:fix/flaky-hedgemarket-test

Conversation

@Bortlesboat
Copy link
Copy Markdown
Contributor

Summary

  • Fixes fix flaky ci test #2231TestHedgeMarket_startAndHedge was flaky in CI
  • Root cause: 10ms hedge ticker could fire concurrently with positionDeltaC channel deltas, causing accumulated quantities to mismatch gomock expectations
  • Fix: replaced shared 10ms interval with 1-hour interval local to the test since hedging is driven entirely through positionDeltaC + hedgedC synchronization

Changes

  • pkg/strategy/xmaker/hedgemarket_test.go — 5 lines added, 1 removed

Test plan

  • go test ./pkg/strategy/xmaker/ -run TestHedgeMarket_startAndHedge -count=100 passes consistently
  • No changes to production code

…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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 28, 2026

CLA assistant check
All committers have signed the CLA.

@c9s c9s enabled auto-merge March 31, 2026 04:30
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 19.81%. Comparing base (f2badc8) to head (ef2bc66).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4e90e6e...ef2bc66. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@c9s c9s merged commit bfce1dd into c9s:main Mar 31, 2026
5 checks passed
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.

fix flaky ci test

3 participants