Testing in Go: philosophy and tools
Testing in Go: philosophy and tools
Posted May 27, 2020 6:03 UTC (Wed) by kokkoro (guest, #139153)In reply to: Testing in Go: philosophy and tools by phlogistonjohn
Parent article: Testing in Go: philosophy and tools
Defer doesn't work properly with parallel tests. If you do:
func TestFoo(t *testing.T) {
f := NewFoo()
defer f.Close()
for _, c := testCases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
c.func(t, f)
})
}
then f.Close() will be called immediately, concurrent to all of the parallel subtests.
https://github.com/golang/go/issues/17791
