One green run tells you almost nothing about a flaky test. A failure rate tells you more.
This post covers three flaky tests, their failure rates before and after each fix, and how many clean runs it takes to verify a fix.
Everything ran on Windows 11 with Go 1.26 and Node 24, and all numbers come from real runs.
1. A data race in Go: 85 of 300 runs failed
This test starts goroutines that each call Inc() on a shared counter, then checks the total.
type Counter struct { n int }
func ( c * Counter ) Inc ( ) { c . n ++ } func ( c * Counter ) Value ( ) int { return c . n }
func TestConcurrentInc ( t * testing . T ) { c := & Counter { } var wg sync . WaitGroup for i := 0 ; i < 30 ; i ++ { wg . Add ( 1 ) go func ( ) { defer wg . Done ( ) ; c . Inc ( ) } ( ) } wg . Wait ( ) if c . Value ( ) != 30 { t . Fatalf ( "got %d want 30" , c . Value ( ) ) } }
Enter fullscreen mode
Exit fullscreen mode
With 30 goroutines, 85 of 300 runs failed (28%). With 1000 goroutines, 299 of 300 failed.…