From 0a9f1ab8bb68835bf66faf9c7a925003c6087c4e Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Fri, 8 Feb 2013 19:24:50 +0400 Subject: [PATCH] runtime/race: deflake tests With the new scheduler races in the tests are reported during execution of other tests. The change joins goroutines started during the tests. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7310066 --- src/pkg/runtime/race/testdata/mop_test.go | 7 ++++++- src/pkg/runtime/race/testdata/regression_test.go | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pkg/runtime/race/testdata/mop_test.go b/src/pkg/runtime/race/testdata/mop_test.go index fa92182fa2..f2daa37301 100644 --- a/src/pkg/runtime/race/testdata/mop_test.go +++ b/src/pkg/runtime/race/testdata/mop_test.go @@ -745,7 +745,8 @@ func TestRaceCrawl(t *testing.T) { url := "dummyurl" depth := 3 seen := make(map[string]bool) - ch := make(chan int) + ch := make(chan int, 100) + var wg sync.WaitGroup var crawl func(string, int) crawl = func(u string, d int) { nurl := 0 @@ -759,12 +760,16 @@ func TestRaceCrawl(t *testing.T) { urls := [...]string{"a", "b", "c"} for _, uu := range urls { if _, ok := seen[uu]; !ok { + wg.Add(1) go crawl(uu, d-1) nurl++ } } + wg.Done() } + wg.Add(1) go crawl(url, depth) + wg.Wait() } func TestRaceIndirection(t *testing.T) { diff --git a/src/pkg/runtime/race/testdata/regression_test.go b/src/pkg/runtime/race/testdata/regression_test.go index 066ccbb38e..afe8cc5ec2 100644 --- a/src/pkg/runtime/race/testdata/regression_test.go +++ b/src/pkg/runtime/race/testdata/regression_test.go @@ -15,10 +15,13 @@ type LogImpl struct { } func NewLog() (l LogImpl) { + c := make(chan bool) go func() { _ = l + c <- true }() l = LogImpl{} + <-c return } -- 2.48.1