mirror of
https://github.com/golang/go
synced 2024-11-17 21:44:43 -07:00
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>
This commit is contained in:
parent
c8313d4fa8
commit
eaf0e3d465
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user