Skip to content

test: fix flaky TestDeps by using group output#2926

Open
vmaerten wants to merge 1 commit into
mainfrom
test/fix-flaky-testdeps
Open

test: fix flaky TestDeps by using group output#2926
vmaerten wants to merge 1 commit into
mainfrom
test/fix-flaky-testdeps

Conversation

@vmaerten

@vmaerten vmaerten commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary

TestDeps was intermittently failing in CI.

Root cause: TestDeps runs its dependencies in parallel (via errgroup in runDeps), and they all write to the same buffer. With the default interleaved output style nothing is serialized, and the mvdan/sh echo builtin writes the content and the trailing newline as two separate Write calls. The test's SyncBuffer locks each individual Write but not the content+newline pair, so two concurrent commands can interleave at the sub-line level, corrupting the captured output.

Fix: capture TestDeps output with the group style, which buffers each command separately and flushes it atomically. Every line stays intact, ordering remains irrelevant (the test already sorts via PPSortedLines), and the golden fixture is unchanged. This matches the existing pattern already used elsewhere in executor_test.go.

No production code changes; the sub-line interleaving is expected behavior of the interleaved output style, for which output: group is the documented clean-output answer.

Test plan

  • go test -run '^TestDeps$' -count=500 -race . → 0 failures (was ~17/300 before)
  • git diff on testdata/deps/ is empty (golden unchanged)
  • go test ./... → no failures

@vmaerten
vmaerten marked this pull request as ready for review July 20, 2026 16:29
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