]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/race: deflake tests
authorDmitriy Vyukov <dvyukov@google.com>
Fri, 8 Feb 2013 15:24:50 +0000 (19:24 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Fri, 8 Feb 2013 15:24:50 +0000 (19:24 +0400)
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
src/pkg/runtime/race/testdata/regression_test.go

index fa92182fa26518acda7c9154a935a6f013ba8469..f2daa3730197784fcbbd83fa96be687ca1c49f26 100644 (file)
@@ -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) {
index 066ccbb38e6d33d8da1bda1a2557497f6438864f..afe8cc5ec250cd3f5f0e5a3fa3fccac43e585d75 100644 (file)
@@ -15,10 +15,13 @@ type LogImpl struct {
 }
 
 func NewLog() (l LogImpl) {
+       c := make(chan bool)
        go func() {
                _ = l
+               c <- true
        }()
        l = LogImpl{}
+       <-c
        return
 }