Skip to content

bug in parallel tests #466

@yiminc-zz

Description

@yiminc-zz

When enable parallel testing, we would expect the TearDownSuite() to be called after all the tests completed. However, after this commit, 3104bf5
the parallel testing is broken as the TearDownSuite() is called before tests are done.
Here is a simple repro code to repro:

type MyTestSuite struct {
	suite.Suite
}
func TestMySuite(t *testing.T) {
	suite.Run(t, new(MyTestSuite))
}
func (s *MyTestSuite) SetupSuite() {
	fmt.Println("SetupSuite")
}
func (s *MyTestSuite) TearDownSuite() {
	fmt.Println("TearDownSuite")
}
func (s *MyTestSuite) SetupTest() {
	s.T().Parallel()
	fmt.Println("SetupTest")
}
func (s *MyTestSuite) TearDownTest() {
	fmt.Println("TearDownTest")
}
func (s *MyTestSuite) Test_A() {
	time.Sleep(time.Second)
}
func (s *MyTestSuite) Test_B() {
	time.Sleep(time.Second * 2)
}

The output of above tests is:

SetupSuite
TearDownSuite
SetupTest
SetupTest
TearDownTest
TearDownTest

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions