Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WaitGroup to ensure suite.Run() doesn't exit until all tests are done #1447

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func Run(t *testing.T, suite TestingSuite) {
tests := []testing.InternalTest{}
methodFinder := reflect.TypeOf(suite)
suiteName := methodFinder.Elem().Name()
wg := new(sync.WaitGroup)

for i := 0; i < methodFinder.NumMethod(); i++ {
method := methodFinder.Method(i)
Expand Down Expand Up @@ -160,6 +161,9 @@ func Run(t *testing.T, suite TestingSuite) {
test := testing.InternalTest{
Name: method.Name,
F: func(t *testing.T) {
wg.Add(1)
defer wg.Done()

parentT := suite.T()
suite.SetT(t)
defer recoverAndFailOnPanic(t)
Expand Down Expand Up @@ -213,6 +217,10 @@ func Run(t *testing.T, suite TestingSuite) {
}

runTests(t, tests)

// Wait until all tests are finished before returning, so that the stats handling in the `defer` statement above
// will always return accurate results, even if the tests are running in parallel.
wg.Wait()
}

// Filtering method according to set regular expression
Expand Down
Loading