Commit f6d18c5e authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent 699aa37d
...@@ -14,16 +14,16 @@ import ( ...@@ -14,16 +14,16 @@ import (
func TestNoRaceFin(t *testing.T) { func TestNoRaceFin(t *testing.T) {
c := make(chan bool) c := make(chan bool)
go func() { go func() {
x := new(int) x := new(string)
runtime.SetFinalizer(x, func(x *int) { runtime.SetFinalizer(x, func(x *string) {
*x = 42 *x = "foo"
}) })
*x = 66 *x = "bar"
c <- true c <- true
}() }()
<-c <-c
runtime.GC() runtime.GC()
time.Sleep(1e8) time.Sleep(100 * time.Millisecond)
} }
var finVar struct { var finVar struct {
...@@ -34,8 +34,8 @@ var finVar struct { ...@@ -34,8 +34,8 @@ var finVar struct {
func TestNoRaceFinGlobal(t *testing.T) { func TestNoRaceFinGlobal(t *testing.T) {
c := make(chan bool) c := make(chan bool)
go func() { go func() {
x := new(int) x := new(string)
runtime.SetFinalizer(x, func(x *int) { runtime.SetFinalizer(x, func(x *string) {
finVar.Lock() finVar.Lock()
finVar.cnt++ finVar.cnt++
finVar.Unlock() finVar.Unlock()
...@@ -44,7 +44,7 @@ func TestNoRaceFinGlobal(t *testing.T) { ...@@ -44,7 +44,7 @@ func TestNoRaceFinGlobal(t *testing.T) {
}() }()
<-c <-c
runtime.GC() runtime.GC()
time.Sleep(1e8) time.Sleep(100 * time.Millisecond)
finVar.Lock() finVar.Lock()
finVar.cnt++ finVar.cnt++
finVar.Unlock() finVar.Unlock()
...@@ -54,14 +54,14 @@ func TestRaceFin(t *testing.T) { ...@@ -54,14 +54,14 @@ func TestRaceFin(t *testing.T) {
c := make(chan bool) c := make(chan bool)
y := 0 y := 0
go func() { go func() {
x := new(int) x := new(string)
runtime.SetFinalizer(x, func(x *int) { runtime.SetFinalizer(x, func(x *string) {
y = 42 y = 42
}) })
c <- true c <- true
}() }()
<-c <-c
runtime.GC() runtime.GC()
time.Sleep(1e8) time.Sleep(100 * time.Millisecond)
y = 66 y = 66
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment