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

Conversation

benvernier-sc
Copy link

Summary

Add a WaitGroup to suite's Run function to better support parallel tests

Changes

  • Added a WaitGroup in suite's Run function
  • Add to the WaitGroup for each test in the suite
  • Use defer wg.Done() as the very last defer of each test to appropriately mark it as done
  • Add a call to wg.Wait() before returning from Run to ensure that Run's defer statement are only executed after all tests have completed

Motivation

When using a suite with multiple tests that are defined as parallel tests (t.Parallel() called), the suite's stats reporting is inaccurate because the WithStats method is called from a defer in the Run method, which exits before all tests have completed.

Related issues

@benvernier-sc benvernier-sc marked this pull request as draft August 1, 2023 06:32
@benvernier-sc benvernier-sc marked this pull request as ready for review August 1, 2023 06:37
@benvernier-sc benvernier-sc marked this pull request as draft August 2, 2023 00:51
@dolmen dolmen added concurrency pkg-suite Change related to package testify/suite bug labels Aug 11, 2023
@dolmen
Copy link
Collaborator

dolmen commented Aug 11, 2023

Related to #1139.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug concurrency pkg-suite Change related to package testify/suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants