-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testing: fix panicking tests hang if Cleanup calls FailNow
Previously, it was impossible to call FailNow in a Cleanup. Because it can terminate a panicking goroutine and cause its parent hangs on t.signal channel. This CL sends the signal in a deferred call to prevent the hang. Fixes #41355 Change-Id: I4552d3a7ea763ef86817bf9b50c0e37fb34bf20f Reviewed-on: https://go-review.googlesource.com/c/go/+/254637 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Emmanuel Odeke <emm.odeke@gmail.com>
- Loading branch information
1 parent
5764653
commit a408139
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# For issue 41355 | ||
[short] skip | ||
|
||
! go test -v cleanup_failnow/panic_nocleanup_test.go | ||
stdout '(?s)panic: die \[recovered\].*panic: die' | ||
! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die' | ||
|
||
! go test -v cleanup_failnow/panic_withcleanup_test.go | ||
stdout '(?s)panic: die \[recovered\].*panic: die' | ||
! stdout '(?s)panic: die \[recovered\].*panic: die.*panic: die' | ||
|
||
-- cleanup_failnow/panic_nocleanup_test.go -- | ||
package panic_nocleanup_test | ||
import "testing" | ||
func TestX(t *testing.T) { | ||
t.Run("x", func(t *testing.T) { | ||
panic("die") | ||
}) | ||
} | ||
|
||
-- cleanup_failnow/panic_withcleanup_test.go -- | ||
package panic_withcleanup_test | ||
import "testing" | ||
func TestCleanupWithFailNow(t *testing.T) { | ||
t.Cleanup(func() { | ||
t.FailNow() | ||
}) | ||
t.Run("x", func(t *testing.T) { | ||
t.Run("y", func(t *testing.T) { | ||
panic("die") | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters