diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-11-30 11:00:56 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-12-01 21:27:08 +0000 |
| commit | 26b1694d9ad06b4f237526f507494edb948a4866 (patch) | |
| tree | a623ab3a5d3054485971121e07cd5f933c657d80 /src/testing/testing_test.go | |
| parent | ecb9d9b95ccba900de9504b3699a219c84b0aa96 (diff) | |
| download | go-26b1694d9ad06b4f237526f507494edb948a4866.tar.xz | |
testing: add regression tests for reentrant calls to T.Run
These tests represent two patterns of usage, found in Google-internal
tests, that deadlocked after CL 506755.
TestConcurrentRun is a minor variation on TestParallelSub, with the
additional expectation that the concurrent calls to Run (without
explicit calls to Parallel) proceed without blocking. It replaces
TestParallelSub.
TestParentRun is similar, but instead of calling Run concurrently it
calls Run from within the subtest body. It almost certainly represents
an accidental misuse of T.Run, but since that pattern used to run to
completion we don't want to break it accidentally. (Perhaps it should
be diagnosed with a vet check instead?)
While we are testing concurrency, this also cleans up
TestConcurrentCleanup to use a clearer synchronization pattern.
Fixes #64402.
Change-Id: I14fc7e7085a994c284509eac28190c3a8feb04cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/546019
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/testing/testing_test.go')
| -rw-r--r-- | src/testing/testing_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go index 166ebb7ab3..d3822dfd57 100644 --- a/src/testing/testing_test.go +++ b/src/testing/testing_test.go @@ -780,3 +780,35 @@ func parseRunningTests(out []byte) (runningTests []string, ok bool) { return nil, false } + +func TestConcurrentRun(t *testing.T) { + // Regression test for https://go.dev/issue/64402: + // this deadlocked after https://go.dev/cl/506755. + + block := make(chan struct{}) + var ready, done sync.WaitGroup + for i := 0; i < 2; i++ { + ready.Add(1) + done.Add(1) + go t.Run("", func(*testing.T) { + ready.Done() + <-block + done.Done() + }) + } + ready.Wait() + close(block) + done.Wait() +} + +func TestParentRun(t1 *testing.T) { + // Regression test for https://go.dev/issue/64402: + // this deadlocked after https://go.dev/cl/506755. + + t1.Run("outer", func(t2 *testing.T) { + t2.Log("Hello outer!") + t1.Run("not_inner", func(t3 *testing.T) { // Note: this is t1.Run, not t2.Run. + t3.Log("Hello inner!") + }) + }) +} |
