Skip to content

test: make EWMA failure-rate cases deterministic with a seeded RNG#26

Merged
costela merged 1 commit into
mainfrom
test/deterministic-ewma-seed
Jun 29, 2026
Merged

test: make EWMA failure-rate cases deterministic with a seeded RNG#26
costela merged 1 commit into
mainfrom
test/deterministic-ewma-seed

Conversation

@costela

@costela costela commented Jun 26, 2026

Copy link
Copy Markdown
Member

What

Makes the two TestBreaker_Observe_State/... subtests that were labelled (EWMA flaky) deterministic.

Why

They failed intermittently (~13% of runs). Two causes:

  1. The unseeded global math/rand source.
  2. t.Parallel() subtests all drawing from that shared global source — so even a fixed global seed would interleave nondeterministically.

A flaky test in CI trains everyone to reflexively re-run, which is how a real failure eventually slips through.

How

  • Each subtest gets its own *rand.Rand seeded with a fixed testSeed, threaded through failureFunc.
  • Same realistic mixed traffic every run, reproducibly. "flaky" labels removed.

Notes

Test-only change; no production code touched.

🤖 Generated with Claude Code

Two subtests in TestBreaker_Observe_State were named "(EWMA flaky)" and
failed intermittently (~13% of runs). The flakiness had two causes: the
unseeded global math/rand source, and t.Parallel() subtests all drawing
from that shared global source, so even a fixed global seed would interleave
nondeterministically.

Give each subtest its own *rand.Rand seeded with a fixed testSeed and thread
it through failureFunc. The statistical scenarios now exercise the same
realistic mixed traffic on every run, deterministically, so the "flaky"
labels are dropped.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes flakiness from two EWMA-related subtests in TestBreaker_Observe_State by eliminating shared use of the global math/rand source under t.Parallel(), making the statistically-driven stages deterministic and repeatable.

Changes:

  • Introduces a fixed testSeed constant for deterministic test randomness.
  • Refactors stage failureFunc helpers/signatures to accept a per-subtest *rand.Rand.
  • Creates a per-subtest RNG (rand.New(rand.NewSource(testSeed))) so parallel subtests don’t interleave draws.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@costela costela merged commit 121d79a into main Jun 29, 2026
3 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.

3 participants