]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/race: deflake test
authorDmitry Vyukov <dvyukov@google.com>
Mon, 9 May 2016 13:11:24 +0000 (15:11 +0200)
committerDmitry Vyukov <dvyukov@google.com>
Mon, 9 May 2016 14:50:18 +0000 (14:50 +0000)
The test sometimes fails on builders.
The test uses sleeps to establish the necessary goroutine
execution order. If sleeps undersleep/oversleep
the race is still reported, but it can be reported when the
main test goroutine returns. In such case test driver
can't match the race with the test and reports failure.

Wait for both test goroutines to ensure that the race
is reported in the test scope.

Fixes #15579

Change-Id: I0b9bec0ebfb0c127d83eb5325a7fe19ef9545050
Reviewed-on: https://go-review.googlesource.com/22951
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/race/testdata/chan_test.go

index cddd9a6e782f2a2e5d0aded50f9032225baf7eef..449191639e6180867ad4583f331b10e567e30229 100644 (file)
@@ -285,17 +285,20 @@ func TestRaceChanWrongClose(t *testing.T) {
        v1 := 0
        v2 := 0
        c := make(chan int, 1)
+       done := make(chan bool)
        go func() {
                defer func() {
                        recover()
                }()
                v1 = 1
                c <- 1
+               done <- true
        }()
        go func() {
                time.Sleep(1e7)
                v2 = 2
                close(c)
+               done <- true
        }()
        time.Sleep(2e7)
        if _, who := <-c; who {
@@ -303,6 +306,8 @@ func TestRaceChanWrongClose(t *testing.T) {
        } else {
                v1 = 2
        }
+       <-done
+       <-done
 }
 
 func TestRaceChanSendClose(t *testing.T) {