Skip to content

Fix the Git service test racing every other test that registers services - #349

Merged
Timmoth merged 1 commit into
stagingfrom
fix/flaky-git-static
Sep 29, 2026
Merged

Timmoth merged 1 commit into
stagingfrom
fix/flaky-git-static

Conversation

@Timmoth

@Timmoth Timmoth commented Sep 29, 2026

Copy link
Copy Markdown
Owner

GitConfigurationTests.Git_Token_Set_Registers_LibGit2GitRepository_And_Flips_HasGitServices fails roughly one full-suite run in three, and passes in isolation every time.

Cause

Registering RackPeek's services writes process-wide statics as a side effect — RpkConstants.HasGitServices among them. Harmless in production, where a process registers once. A race in a test run, where dozens of classes register with different configuration.

Three groups mutate it, from three different xUnit collections:

Where Collection
Tests/Git/GitConfigurationTests.cs "Git static state"
Tests/EndToEnd/Infra/YamlCliTestHost.cs "Yaml CLI tests" (parallelisation already off)
Tests/Api/ApiTestBase.cs none — each class its own collection

Collections run in parallel with each other, so whichever registered last won. The Git test asserts the flag is true and would read whatever an API test had set microseconds earlier.

Fix

All three now share one collection with parallelisation off. It's named for the shared state rather than for the YAML CLI, because membership is decided by "does this touch the statics", not by what the test nominally exercises.

Evidence

  • Baseline: failed 1 of 2 full runs.
  • After: 6 of 6 green.
  • Cost: ~3s on a 15s suite.

Worth doing before a release, since the release guide's first gate is "staging CI is green" — a one-in-three flake makes that gate unreliable exactly when it matters most.

🤖 Generated with Claude Code

…ices

Registering RackPeek's services writes process-wide statics as a side effect,
RpkConstants.HasGitServices among them. That is harmless in production, where a
process registers once, and a race in a test run, where dozens of classes
register with different configuration.

Three groups were mutating it from three different xUnit collections — the Git
tests, the YAML CLI host, and the API tests — and collections run in parallel
with each other, so whichever ran last won. Git_Token_Set_Registers_...
asserted the flag was true and read whatever an API test had just set, failing
roughly one full-suite run in three while passing in isolation every time.

They now share one collection with parallelisation off, named for the shared
state rather than for the YAML CLI, because membership is decided by "does this
touch the statics" rather than by what the test nominally exercises.

Six consecutive full runs green, against a baseline that failed one run in two.
Costs about three seconds on a fifteen-second suite.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Timmoth
Timmoth merged commit 48378e4 into staging Sep 29, 2026
6 checks passed
@Timmoth
Timmoth deleted the fix/flaky-git-static branch September 29, 2026 07:24
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.

1 participant