Commit 0a9f1ab8 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent 45636db0
...@@ -745,7 +745,8 @@ func TestRaceCrawl(t *testing.T) { ...@@ -745,7 +745,8 @@ func TestRaceCrawl(t *testing.T) {
url := "dummyurl" url := "dummyurl"
depth := 3 depth := 3
seen := make(map[string]bool) seen := make(map[string]bool)
ch := make(chan int) ch := make(chan int, 100)
var wg sync.WaitGroup
var crawl func(string, int) var crawl func(string, int)
crawl = func(u string, d int) { crawl = func(u string, d int) {
nurl := 0 nurl := 0
...@@ -759,12 +760,16 @@ func TestRaceCrawl(t *testing.T) { ...@@ -759,12 +760,16 @@ func TestRaceCrawl(t *testing.T) {
urls := [...]string{"a", "b", "c"} urls := [...]string{"a", "b", "c"}
for _, uu := range urls { for _, uu := range urls {
if _, ok := seen[uu]; !ok { if _, ok := seen[uu]; !ok {
wg.Add(1)
go crawl(uu, d-1) go crawl(uu, d-1)
nurl++ nurl++
} }
} }
wg.Done()
} }
wg.Add(1)
go crawl(url, depth) go crawl(url, depth)
wg.Wait()
} }
func TestRaceIndirection(t *testing.T) { func TestRaceIndirection(t *testing.T) {
......
...@@ -15,10 +15,13 @@ type LogImpl struct { ...@@ -15,10 +15,13 @@ type LogImpl struct {
} }
func NewLog() (l LogImpl) { func NewLog() (l LogImpl) {
c := make(chan bool)
go func() { go func() {
_ = l _ = l
c <- true
}() }()
l = LogImpl{} l = LogImpl{}
<-c
return return
} }
......
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