You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
testing: API for deferring a cleanup step when subtests use Parallel #31651
Unfortunately this is not correct - cleanup will run too early, before the subtests finish (in fact, before they even get passed the Parallel() call).
Most CockroachDB tests use a defer leaktest.AfterTest(t)() call in the beginning that checks for stray goroutines; using Parallel() in subtests breaks that pattern.
My proposal is to add an API to T that runs a cleanup step after all subtests finish; defer cleanup() would become t.Defer(cleanup()) or similar.
Also, this gotcha should be called out in the documentation (#23368 is related).
Ah.. I found this in the higher-level documentation:
funcTestTeardownParallel(t*testing.T) {
// This Run will not return until the parallel tests finish.t.Run("group", func(t*testing.T) {
t.Run("Test1", parallelTest1)
t.Run("Test2", parallelTest2)
t.Run("Test3", parallelTest3)
})
// <tear-down code>
}
This is a good workaround for this problem (though it would still be better if there was an explicit API). Either way, I think there should be a pointer to this information in the documentation of Parallel.
Activity
RaduBerinde commentedon Apr 24, 2019
Ah.. I found this in the higher-level documentation:
This is a good workaround for this problem (though it would still be better if there was an explicit API). Either way, I think there should be a pointer to this information in the documentation of
Parallel.katiehockman commentedon Apr 29, 2019
/cc @mpvl
Squashed commit of the following:
Squashed commit of the following:
gopherbot commentedon Jan 15, 2020
Change https://golang.org/cl/214822 mentions this issue:
testing: don't run Cleanup functions until parallel subtests complete