]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: test Goexit/defer iteraction.
authorKeith Randall <khr@golang.org>
Mon, 15 Sep 2014 22:09:17 +0000 (15:09 -0700)
committerKeith Randall <khr@golang.org>
Mon, 15 Sep 2014 22:09:17 +0000 (15:09 -0700)
Make sure Goexit runs defers.
Make sure recover() during a Goexit defer returns nil.

LGTM=dvyukov, bradfitz
R=golang-codereviews, dvyukov, bradfitz, khr
CC=golang-codereviews
https://golang.org/cl/140650043

src/runtime/crash_test.go

index a86a3b7904e4e7439d99cff9cc12bb30ee8c9613..d1577fb5fede0276377381017a405d714bbb7565 100644 (file)
@@ -159,6 +159,22 @@ func TestGoexitCrash(t *testing.T) {
        }
 }
 
+func TestGoexitDefer(t *testing.T) {
+       c := make(chan struct{})
+       go func() {
+               defer func() {
+                       r := recover()
+                       if r != nil {
+                               t.Errorf("non-nil recover during Goexit")
+                       }
+                       c <- struct{}{}
+               }()
+               runtime.Goexit()
+       }()
+       // Note: if the defer fails to run, we will get a deadlock here
+       <-c
+}
+
 func TestGoNil(t *testing.T) {
        output := executeTest(t, goNilSource, nil)
        want := "go of nil func value"