Open bstpierre opened 2 years ago
Parallel tests and subtests are broken in a number of ways with the suite package in the current release. This race, wrong subtest names in failed assertions, cleanup being run before the end of the test...
Does this branch work well for you? It is a breaking API change in the suite package but I hope that we can adopt it for testify v2 as it should allow us to fix a lot of the problems with parallel tests.
@brackendawson Yes. When I modify the test program above to match the new api and run against that branch, it runs without errors.
package main
import (
"testing"
"github.com/stretchr/testify/suite"
)
type MainSuite struct{}
func (s *MainSuite) TestA(t *suite.T) {
t.Parallel()
for x := 0; x < 1000000; x++ {
t.Equal(x, add(x, 0))
}
}
func (s *MainSuite) TestB(t *suite.T) {
t.Parallel()
for x := 0; x < 1000000; x++ {
t.Equal(x+1, add(x, 1))
}
}
func Test_Main(t *testing.T) {
suite.Run(t, new(MainSuite))
}
Any update on the ETA of this fix?
The fix for this wold require testify/v2/suite
, this is not expected soon. For now; parallel tests and subtests are not supportable with testify/suite
.
Suite v2 will have to happen elsewhere. There is already too much maintenance work here on assert and mock.
Running suite.Run() when test cases have called
suite.T().Parallel()
triggers a data race warning when usinggo test -race
.==> go.mod <==
==> main.go <==
==> main_test.go <==
Running the test with the race detector:
Based on a quick look at the code, it seems like the usage of
suite.SetT()
in various places in suite.Run is the cause of the race.