diff options
| author | Russ Cox <rsc@golang.org> | 2024-05-24 09:33:45 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-05-24 16:41:13 +0000 |
| commit | f85c40438fea862be03d2de4b58ed3afe7cfe033 (patch) | |
| tree | 199325218768f9bd674f77dcfe9f3312ecff164f /src/runtime/ehooks_test.go | |
| parent | 378c48df3b485da1ed287f59e5d1f59ad232e554 (diff) | |
| download | go-f85c40438fea862be03d2de4b58ed3afe7cfe033.tar.xz | |
internal/runtime/exithook: make safe for concurrent os.Exit
Real programs can call os.Exit concurrently from multiple goroutines.
Make internal/runtime/exithook not crash in that case.
The throw on panic also now runs in the deferred context,
so that we will see the full stack trace that led to the panic.
That should give us more visibility into the flaky failures on
bugs #55167 and #56197 as well.
Fixes #67631.
Change-Id: Iefdf71b3a3b52a793ca88d89a9c270eb50ece094
Reviewed-on: https://go-review.googlesource.com/c/go/+/588235
Reviewed-by: Than McIntosh <thanm@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/ehooks_test.go')
| -rw-r--r-- | src/runtime/ehooks_test.go | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/runtime/ehooks_test.go b/src/runtime/ehooks_test.go index 2265256a0b..4beb20b0be 100644 --- a/src/runtime/ehooks_test.go +++ b/src/runtime/ehooks_test.go @@ -28,32 +28,36 @@ func TestExitHooks(t *testing.T) { scenarios := []struct { mode string expected string - musthave string + musthave []string }{ { mode: "simple", expected: "bar foo", - musthave: "", }, { mode: "goodexit", expected: "orange apple", - musthave: "", }, { mode: "badexit", expected: "blub blix", - musthave: "", }, { - mode: "panics", - expected: "", - musthave: "fatal error: exit hook invoked panic", + mode: "panics", + musthave: []string{ + "fatal error: exit hook invoked panic", + "main.testPanics", + }, + }, + { + mode: "callsexit", + musthave: []string{ + "fatal error: exit hook invoked exit", + }, }, { - mode: "callsexit", + mode: "exit2", expected: "", - musthave: "fatal error: exit hook invoked exit", }, } @@ -71,20 +75,18 @@ func TestExitHooks(t *testing.T) { out, _ := cmd.CombinedOutput() outs := strings.ReplaceAll(string(out), "\n", " ") outs = strings.TrimSpace(outs) - if s.expected != "" { - if s.expected != outs { - t.Logf("raw output: %q", outs) - t.Errorf("failed%s mode %s: wanted %q got %q", bt, - s.mode, s.expected, outs) - } - } else if s.musthave != "" { - if !strings.Contains(outs, s.musthave) { - t.Logf("raw output: %q", outs) - t.Errorf("failed mode %s: output does not contain %q", - s.mode, s.musthave) + if s.expected != "" && s.expected != outs { + t.Fatalf("failed%s mode %s: wanted %q\noutput:\n%s", bt, + s.mode, s.expected, outs) + } + for _, need := range s.musthave { + if !strings.Contains(outs, need) { + t.Fatalf("failed mode %s: output does not contain %q\noutput:\n%s", + s.mode, need, outs) } - } else { - panic("badly written scenario") + } + if s.expected == "" && s.musthave == nil && outs != "" { + t.Errorf("failed mode %s: wanted no output\noutput:\n%s", s.mode, outs) } } } |
