From: Daniel S. Fava Date: Fri, 12 Feb 2021 08:54:50 +0000 (+0100) Subject: testing/race: fixing intermittent test failure X-Git-Tag: go1.17beta1~1410 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=aaed6cbced;p=gostls13.git testing/race: fixing intermittent test failure Test NoRaceMutexPureHappensBefore in runtime/race/testdata/mutex_test.go expects the second spawned goroutine to run after the first. The test attempts to force this scheduling with a 10 millisecond wait. Following a suggestion by Bryan Mills, we force this scheduling using a shared variable whose access take place within the existing mutex. Fixes #35745. Change-Id: Ib23ec51492ecfeed4752e020401dd25755a669ed Reviewed-on: https://go-review.googlesource.com/c/go/+/291292 Reviewed-by: Bryan C. Mills Reviewed-by: Dmitry Vyukov Trust: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot --- diff --git a/src/runtime/race/testdata/mutex_test.go b/src/runtime/race/testdata/mutex_test.go index cbed2d370c..9dbed9a2c9 100644 --- a/src/runtime/race/testdata/mutex_test.go +++ b/src/runtime/race/testdata/mutex_test.go @@ -78,16 +78,23 @@ func TestNoRaceMutexPureHappensBefore(t *testing.T) { var mu sync.Mutex var x int16 = 0 _ = x + written := false ch := make(chan bool, 2) go func() { x = 1 mu.Lock() + written = true mu.Unlock() ch <- true }() go func() { - <-time.After(1e5) + time.Sleep(100 * time.Microsecond) mu.Lock() + for !written { + mu.Unlock() + time.Sleep(100 * time.Microsecond) + mu.Lock() + } mu.Unlock() x = 1 ch <- true