Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Sub-tests Done Right: t.Run, t.Parallel, and the Cleanup-Order Trap

DEV Community·Gabriel Anhaia·25 days ago
#zv6eOd0f
#rule#go#testing#concurrency#parallel#cleanup
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub A backend team I talked to last quarter had a flaky integration suite that passed locally and failed once a week in CI. The failure was always the same: a Postgres test row that should not exist still existed when a later test queried for it. They added sleeps. They added retries. They added a "skip flaky" tag. The test stayed flaky for four months. The bug was four lines of test setup. A parent test opened a shared transaction, registered t.Cleanup to roll it back, then spawned three sub-tests with t.Parallel() . Sometimes the rollback ran while a parallel child was still mid-INSERT. Race detector said nothing. go test -v said the parent passed. The data said otherwise.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More