fix(internal/civisibility): avoid tests-only race condition on CIVis reset#4744
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files🚀 New features to boost your workflow:
|
🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 7460e1f | Docs | Datadog PR Page | Give us feedback! |
…rves-suite-level-unskippable
BenchmarksBenchmark execution time: 2026-05-11 15:56:08 Comparing candidate commit 7460e1f in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 273 metrics, 2 unstable metrics, 1 flaky benchmarks without significant changes.
|
55c1586
into
main
What does this PR do?
In
resetCIVisibilityStateForTesting, replacesgetSearchCommitsFunc = getSearchCommits(the real git function) with a stub that immediately returns (nil, nil, false) ("no commits, upload skipped").The upload goroutine short-circuits in
uploadRepositoryChangesWithHooksat the!IsOkcheck and exits immediately — never readingciVisibilityClient. No concurrent reader, no race. Tests that need real commit behavior already overridegetSearchCommitsFuncafter reset.Motivation
Root cause:
resetCIVisibilityStateForTestingresetssettingsInitializationOnceto fresh, so the first call toGetImpactedTestsAnalyzer()insideSetTestFunctriggers the real settings initialization. That spawns an upload goroutine which callsgetSearchCommits()→utils.GetLastLocalGitCommitShas()(git subprocess, slow) →ciVisibilityClient.GetCommits(). When the test cleanup then runsciVisibilityClient = nil, the race detector fires.The race is timing-dependent: fast on Mac (goroutine finishes first), caught more often in CI under load or with race-detector overhead widening the window.
Reviewer's Checklist
make lintlocally.make testlocally.make generatelocally.make fix-moduleslocally.Unsure? Have a question? Request a review!