]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: remove arbitrary timeouts in finalizer tests
authorBryan C. Mills <bcmills@google.com>
Thu, 8 Dec 2022 13:24:57 +0000 (08:24 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 8 Dec 2022 14:19:25 +0000 (14:19 +0000)
These short timeouts can overrun due to system scheduling delay
(or GC latency) on a slow or heavily-loaded host.

Moreover, if the test deadlocks we will probably want to know what the
GC goroutines were doing at the time. With an arbitrary timeout, we
never get that information; however, if we allow the test to time out
completely we will get a goroutine dump (and, if GOTRACEBACK is
configured in the environment, that may even include GC goroutines).

Fixes #57166.

Change-Id: I136501883373c3ce4e250dc8340c60876b375f44
Reviewed-on: https://go-review.googlesource.com/c/go/+/456118
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/mfinal_test.go

index 902ccc57f87880be9d5ac480ebe930f895d0617b..61d625ac27775516abfc1a27134fdeb4d395fbb7 100644 (file)
@@ -53,7 +53,7 @@ func TestFinalizerType(t *testing.T) {
                }},
        }
 
-       for i, tt := range finalizerTests {
+       for _, tt := range finalizerTests {
                done := make(chan bool, 1)
                go func() {
                        // allocate struct with pointer to avoid hitting tinyalloc.
@@ -71,11 +71,7 @@ func TestFinalizerType(t *testing.T) {
                }()
                <-done
                runtime.GC()
-               select {
-               case <-ch:
-               case <-time.After(time.Second * 4):
-                       t.Errorf("#%d: finalizer for type %T didn't run", i, tt.finalizer)
-               }
+               <-ch
        }
 }
 
@@ -109,11 +105,7 @@ func TestFinalizerInterfaceBig(t *testing.T) {
        }()
        <-done
        runtime.GC()
-       select {
-       case <-ch:
-       case <-time.After(4 * time.Second):
-               t.Errorf("finalizer for type *bigValue didn't run")
-       }
+       <-ch
 }
 
 func fin(v *int) {
@@ -188,11 +180,7 @@ func TestEmptySlice(t *testing.T) {
        fin := make(chan bool, 1)
        runtime.SetFinalizer(y, func(z *objtype) { fin <- true })
        runtime.GC()
-       select {
-       case <-fin:
-       case <-time.After(4 * time.Second):
-               t.Errorf("finalizer of next object in memory didn't run")
-       }
+       <-fin
        xsglobal = xs // keep empty slice alive until here
 }
 
@@ -220,11 +208,7 @@ func TestEmptyString(t *testing.T) {
        // set finalizer on string contents of y
        runtime.SetFinalizer(y, func(z *objtype) { fin <- true })
        runtime.GC()
-       select {
-       case <-fin:
-       case <-time.After(4 * time.Second):
-               t.Errorf("finalizer of next string in memory didn't run")
-       }
+       <-fin
        ssglobal = ss // keep 0-length string live until here
 }