Menu

1 / 2

Running the same test 300 times: what a 28% flake looks like

DEV Community: go·Vachila 64·7 days ago
#koJOLVbH
#devtogo#devto#dev#runs#test
Long article (1015 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

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