aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/crash_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2017-06-06 17:31:57 -0700
committerIan Lance Taylor <iant@golang.org>2017-06-07 00:55:56 +0000
commitb5a0f7156845302040746ebcb71304f6cb03ba40 (patch)
tree13eb6a6c854f796fcae0fa203f6cea6b8bdc2fd7 /src/runtime/crash_test.go
parent703a9baf5c210ac3955ddaa9df1efcdb2786ab1d (diff)
downloadgo-b5a0f7156845302040746ebcb71304f6cb03ba40.tar.gz
go-b5a0f7156845302040746ebcb71304f6cb03ba40.zip
runtime: deflake TestPanicRace
The test is inherently racy, and for me fails about 0.05% of the time. So only fail the test if it fails ten times in a row. Fixes #20594 Change-Id: I3b3f7598f2196f7406f1a3937f38f21ff0c0e4b5 Reviewed-on: https://go-review.googlesource.com/45020 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/crash_test.go')
-rw-r--r--src/runtime/crash_test.go43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go
index b08dd87d9b..7753809d45 100644
--- a/src/runtime/crash_test.go
+++ b/src/runtime/crash_test.go
@@ -579,21 +579,38 @@ func TestPanicRace(t *testing.T) {
t.Fatal(err)
}
- got, err := testEnv(exec.Command(exe, "PanicRace")).CombinedOutput()
- if err == nil {
- t.Error("program exited successfully, should have failed")
- }
+ // The test is intentionally racy, and in my testing does not
+ // produce the expected output about 0.05% of the time.
+ // So run the program in a loop and only fail the test if we
+ // get the wrong output ten times in a row.
+ const tries = 10
+retry:
+ for i := 0; i < tries; i++ {
+ got, err := testEnv(exec.Command(exe, "PanicRace")).CombinedOutput()
+ if err == nil {
+ t.Logf("try %d: program exited successfully, should have failed", i+1)
+ continue
+ }
- t.Logf("%s\n", got)
+ if i > 0 {
+ t.Logf("try %d:\n", i+1)
+ }
+ t.Logf("%s\n", got)
- wants := []string{
- "panic: crash",
- "PanicRace",
- "created by ",
- }
- for _, want := range wants {
- if !bytes.Contains(got, []byte(want)) {
- t.Errorf("did not find expected string %q", want)
+ wants := []string{
+ "panic: crash",
+ "PanicRace",
+ "created by ",
+ }
+ for _, want := range wants {
+ if !bytes.Contains(got, []byte(want)) {
+ t.Logf("did not find expected string %q", want)
+ continue retry
+ }
}
+
+ // Test generated expected output.
+ return
}
+ t.Errorf("test ran %d times without producing expected output", tries)
}