diff options
| author | Lasse Folger <lassefolger@google.com> | 2023-11-24 15:30:07 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-11-27 16:49:24 +0000 |
| commit | 6317fb41e920cc593620d4b9a55376472fc02c07 (patch) | |
| tree | 5008e5b12850909a494a2bc9e186fa78d85a620a /src/testing/panic_test.go | |
| parent | d961b12be9001cf8dbf8f52847607dbf84d94f8d (diff) | |
| download | go-6317fb41e920cc593620d4b9a55376472fc02c07.tar.xz | |
Revert "testing: simplify concurrency and cleanup logic"
reverts CL 506755
Reason for revert: This leads to deadlocks of tests in Google internal testing
For #64402
Change-Id: I78329fc9dcc2377e7e880b264ac1d18d577ef99a
Reviewed-on: https://go-review.googlesource.com/c/go/+/544895
Auto-Submit: Bryan Mills <bcmills@google.com>
Auto-Submit: Lasse Folger <lassefolger@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/testing/panic_test.go')
| -rw-r--r-- | src/testing/panic_test.go | 85 |
1 files changed, 37 insertions, 48 deletions
diff --git a/src/testing/panic_test.go b/src/testing/panic_test.go index 82e7087025..6307b84a7a 100644 --- a/src/testing/panic_test.go +++ b/src/testing/panic_test.go @@ -211,68 +211,57 @@ func TestPanicHelper(t *testing.T) { } func TestMorePanic(t *testing.T) { - subprocess := false - if os.Getenv("GO_WANT_HELPER_PROCESS") == "1" { - subprocess = true - } else { - testenv.MustHaveExec(t) - t.Parallel() - } + testenv.MustHaveExec(t) testCases := []struct { - issue int desc string - f func(*testing.T) + flags []string want string }{ { - issue: 48502, - desc: "runtime.Goexit in t.Cleanup after panic", - f: func(t *testing.T) { - t.Cleanup(func() { - t.Log("Goexiting in cleanup") - runtime.Goexit() - }) - t.Parallel() - panic("die") - }, - want: `panic: die [recovered] - panic: die`, + desc: "Issue 48502: call runtime.Goexit in t.Cleanup after panic", + flags: []string{"-test.run=^TestGoexitInCleanupAfterPanicHelper$"}, + want: `panic: die + panic: test executed panic(nil) or runtime.Goexit`, }, { - issue: 48515, - desc: "t.Run in t.Cleanup should trigger panic", - f: func(t *testing.T) { - t.Cleanup(func() { - t.Run("in-cleanup", func(t *testing.T) { - t.Log("must not be executed") - }) - }) - }, - want: `panic: testing: t.Run called during t.Cleanup`, + desc: "Issue 48515: call t.Run in t.Cleanup should trigger panic", + flags: []string{"-test.run=^TestCallRunInCleanupHelper$"}, + want: `panic: testing: t.Run called during t.Cleanup`, }, } for _, tc := range testCases { - tc := tc - t.Run(fmt.Sprintf("issue%v", tc.issue), func(t *testing.T) { - if subprocess { - tc.f(t) - return - } + cmd := exec.Command(os.Args[0], tc.flags...) + cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1") + b, _ := cmd.CombinedOutput() + got := string(b) + want := tc.want + re := makeRegexp(want) + if ok, err := regexp.MatchString(re, got); !ok || err != nil { + t.Errorf("output:\ngot:\n%s\nwant:\n%s", got, want) + } + } +} - t.Parallel() - cmd := testenv.Command(t, os.Args[0], "-test.run="+t.Name()) - cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1") - b, _ := cmd.CombinedOutput() - got := string(b) - t.Logf("%v:\n%s", tc.desc, got) +func TestCallRunInCleanupHelper(t *testing.T) { + if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { + return + } - want := tc.want - re := makeRegexp(want) - if ok, err := regexp.MatchString(re, got); !ok || err != nil { - t.Errorf("wanted:\n%s", want) - } + t.Cleanup(func() { + t.Run("in-cleanup", func(t *testing.T) { + t.Log("must not be executed") }) + }) +} + +func TestGoexitInCleanupAfterPanicHelper(t *testing.T) { + if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { + return } + + t.Cleanup(func() { runtime.Goexit() }) + t.Parallel() + panic("die") } |
