Skip to content

fix(mesi): replace timing-dependent test assertions with deterministic synchronization (#116)#152

Merged
s2x merged 1 commit into
mainfrom
fix/issue-116-flaky-tests
May 4, 2026
Merged

fix(mesi): replace timing-dependent test assertions with deterministic synchronization (#116)#152
s2x merged 1 commit into
mainfrom
fix/issue-116-flaky-tests

Conversation

@s2x
Copy link
Copy Markdown
Contributor

@s2x s2x commented May 4, 2026

Summary

Fixes #116 — removes all timing-dependent assertions (elapsed > N, time.Sleep) from the mesi test suite and replaces them with deterministic channel-based synchronization.

Changes

mesi/include.go — Added rng func(int) int parameter to selectUrl(). When nil, falls back to rand.IntN. Enables deterministic RNG injection in tests.

mesi/fetchUrl_test.go — Fixed 4 tests:

  • TestMESIParseContextPropagation — replaced elapsed > 2s with handlerReached channel (handler must NOT be reached when context is pre-cancelled)
  • TestMESIParseContextCancellationStopsAllGoroutines — same pattern
  • TestMESIParseContextCancellationMidParse — replaced time.Sleep(100ms) + <-time.After(2s) with <-handlerReached -> cancel() -> <-done
  • TestFetchConcurrentContextCancellation — replaced time.Sleep(5s) + elapsed > 1s with select on r.Context().Done()

mesi/include_test.go — Fixed TestSelectUrlChoosesBasedOnRatio:

  • Replaced statistical 10000-iteration 65-95% range check with 4 deterministic subtests using injected RNG

mesi/parser_test.go — Fixed TestMESIParseRespectsTimeout:

  • Replaced time.Sleep(500ms) with select on r.Context().Done() + handlerBlock channel

Verification

  • go vet ./... — clean
  • go test -race ./... — all pass (mesi + middleware)

@s2x s2x merged commit ab651e7 into main May 4, 2026
4 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.

[mesi] Timing-dependent tests are flaky on slow CI runners

1 participant