aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-12-08 08:24:57 -0500
committerGopher Robot <gobot@golang.org>2022-12-08 14:19:25 +0000
commiteaf0e3d4650fd223dec84ee52025c7a82bcb24bd (patch)
tree9ef8e42ad02684316c4158fa2d848e9e46d2751d /src/runtime
parentc8313d4fa8ca04a1844edcb4a6e1f61cf13fd40e (diff)
downloadgo-eaf0e3d4650fd223dec84ee52025c7a82bcb24bd.tar.xz
runtime: remove arbitrary timeouts in finalizer tests
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>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/mfinal_test.go26
1 files changed, 5 insertions, 21 deletions
diff --git a/src/runtime/mfinal_test.go b/src/runtime/mfinal_test.go
index 902ccc57f8..61d625ac27 100644
--- a/src/runtime/mfinal_test.go
+++ b/src/runtime/mfinal_test.go
@@ -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
}