Open idkw opened 1 year ago
@moricho I managed to find the culprit, here's a reproducer:
func TestParallel(t *testing.T) {
t.Parallel()
cases := map[string]struct {
a string
b string
}{
"a": {
"a", "b",
},
"b": {
"a", "b",
},
}
wg := sync.WaitGroup{}
for name, c := range cases {
c := c
wg.Add(1)
go t.Run(name, func(t *testing.T) {
defer wg.Done()
require.Equal(t, "a", c.a)
require.Equal(t, "b", c.b)
})
}
wg.Wait()
}
Basically this is a test I have that require to run all its subtests in parallel. We can't rely on t.Parallel() because the default number of parallel tests depends on the number of CPU cores Here we want all subtests to be run in parallel to trigger the behavior we want to test
Found this workaround to avoid the crash:
for name, c := range cases {
name := name
c := c
wg.Add(1)
go func() {
t.Run(name, func(t *testing.T) {
defer wg.Done()
require.Equal(t, "a", c.a)
require.Equal(t, "b", c.b)
})
}()
}
Some projects trigger this
tparallel
crash. I can't share the source code that triggers this crash however.