aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2013-10-02 12:30:49 -0400
committerRuss Cox <rsc@golang.org>2013-10-02 12:30:49 -0400
commit5f853d7d9407db1aaa7c7d0dfbf3dbd9d5c19093 (patch)
tree04bd400df674c50f80d2e7709c35a76a029732a7 /src/pkg/runtime
parent8d6bc666fb86a45f2f426009b05fc07d3fb1cefc (diff)
downloadgo-5f853d7d9407db1aaa7c7d0dfbf3dbd9d5c19093.tar.xz
runtime: fix finalizer test on amd64
Not scanning the stack by frames means we are reintroducing a few false positives into the collection. Run the finalizer registration in its own goroutine so that stack is guaranteed to be out of consideration in a later collection. This is working around a regression from yesterday's tip, but it's not a regression from Go 1.1. R=golang-dev TBR=golang-dev CC=golang-dev https://golang.org/cl/14290043
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r--src/pkg/runtime/mfinal_test.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/pkg/runtime/mfinal_test.go b/src/pkg/runtime/mfinal_test.go
index ae06dd291a..6efef9bb03 100644
--- a/src/pkg/runtime/mfinal_test.go
+++ b/src/pkg/runtime/mfinal_test.go
@@ -46,17 +46,18 @@ func TestFinalizerType(t *testing.T) {
}
for _, tt := range finalizerTests {
- func() {
+ go func() {
v := new(int)
*v = 97531
runtime.SetFinalizer(tt.convert(v), tt.finalizer)
v = nil
}()
+ time.Sleep(1 * time.Second)
runtime.GC()
select {
case <-ch:
case <-time.After(time.Second * 4):
- t.Errorf("Finalizer of type %T didn't run", tt.finalizer)
+ t.Errorf("finalizer for type %T didn't run", tt.finalizer)
}
}
}
@@ -72,25 +73,27 @@ func TestFinalizerInterfaceBig(t *testing.T) {
t.Skipf("Skipping on non-amd64 machine")
}
ch := make(chan bool)
- func() {
+ go func() {
v := &bigValue{0xDEADBEEFDEADBEEF, true, "It matters not how strait the gate"}
+ old := *v
runtime.SetFinalizer(v, func(v interface{}) {
i, ok := v.(*bigValue)
if !ok {
- t.Errorf("Expected *bigValue from interface{} in finalizer, got %v", *i)
+ t.Errorf("finalizer called with type %T, want *bigValue", v)
}
- if i.fill != 0xDEADBEEFDEADBEEF && i.it != true && i.up != "It matters not how strait the gate" {
- t.Errorf("*bigValue from interface{} has the wrong value: %v\n", *i)
+ if *i != old {
+ t.Errorf("finalizer called with %+v, want %+v", *i, old)
}
close(ch)
})
v = nil
}()
+ time.Sleep(1 * time.Second)
runtime.GC()
select {
case <-ch:
- case <-time.After(time.Second * 4):
- t.Errorf("Finalizer set by SetFinalizer(*bigValue, func(interface{})) didn't run")
+ case <-time.After(4 * time.Second):
+ t.Errorf("finalizer for type *bigValue didn't run")
}
}