mirror of
https://github.com/golang/go
synced 2024-11-23 15:40:06 -07:00
runtime/race: fix finalizer tests
After "runtime: combine small NoScan allocations" finalizers for small objects run more non deterministically. TestRaceFin episodically fails on my darwin/amd64. LGTM=khr R=golang-codereviews, khr, dave CC=golang-codereviews https://golang.org/cl/56970043
This commit is contained in:
parent
699aa37d03
commit
f6d18c5ee9
22
src/pkg/runtime/race/testdata/finalizer_test.go
vendored
22
src/pkg/runtime/race/testdata/finalizer_test.go
vendored
@ -14,16 +14,16 @@ import (
|
||||
func TestNoRaceFin(t *testing.T) {
|
||||
c := make(chan bool)
|
||||
go func() {
|
||||
x := new(int)
|
||||
runtime.SetFinalizer(x, func(x *int) {
|
||||
*x = 42
|
||||
x := new(string)
|
||||
runtime.SetFinalizer(x, func(x *string) {
|
||||
*x = "foo"
|
||||
})
|
||||
*x = 66
|
||||
*x = "bar"
|
||||
c <- true
|
||||
}()
|
||||
<-c
|
||||
runtime.GC()
|
||||
time.Sleep(1e8)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
var finVar struct {
|
||||
@ -34,8 +34,8 @@ var finVar struct {
|
||||
func TestNoRaceFinGlobal(t *testing.T) {
|
||||
c := make(chan bool)
|
||||
go func() {
|
||||
x := new(int)
|
||||
runtime.SetFinalizer(x, func(x *int) {
|
||||
x := new(string)
|
||||
runtime.SetFinalizer(x, func(x *string) {
|
||||
finVar.Lock()
|
||||
finVar.cnt++
|
||||
finVar.Unlock()
|
||||
@ -44,7 +44,7 @@ func TestNoRaceFinGlobal(t *testing.T) {
|
||||
}()
|
||||
<-c
|
||||
runtime.GC()
|
||||
time.Sleep(1e8)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
finVar.Lock()
|
||||
finVar.cnt++
|
||||
finVar.Unlock()
|
||||
@ -54,14 +54,14 @@ func TestRaceFin(t *testing.T) {
|
||||
c := make(chan bool)
|
||||
y := 0
|
||||
go func() {
|
||||
x := new(int)
|
||||
runtime.SetFinalizer(x, func(x *int) {
|
||||
x := new(string)
|
||||
runtime.SetFinalizer(x, func(x *string) {
|
||||
y = 42
|
||||
})
|
||||
c <- true
|
||||
}()
|
||||
<-c
|
||||
runtime.GC()
|
||||
time.Sleep(1e8)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
y = 66
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user