aboutsummaryrefslogtreecommitdiff
path: root/src/sync/waitgroup_test.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2017-02-13 10:17:52 -0500
committerRuss Cox <rsc@golang.org>2017-02-16 16:55:54 +0000
commit83f95b85deb97b1f4643362bcd43bee62fd9cc76 (patch)
tree5330384924d475f54f84352bd9356783715f7c42 /src/sync/waitgroup_test.go
parent863035efceaf33e4b7ebfb162930119534e9e5eb (diff)
downloadgo-83f95b85deb97b1f4643362bcd43bee62fd9cc76.tar.gz
go-83f95b85deb97b1f4643362bcd43bee62fd9cc76.zip
sync: deflake TestWaitGroupMisuse2
Also runs 100X faster on average, because it takes so many fewer attempts to trigger the failure. Fixes #11443. Change-Id: I8c39ee48bb3ff6c36fa63083e04076771b65a80d Reviewed-on: https://go-review.googlesource.com/36841 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Diffstat (limited to 'src/sync/waitgroup_test.go')
-rw-r--r--src/sync/waitgroup_test.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/sync/waitgroup_test.go b/src/sync/waitgroup_test.go
index 8ec34fd343..c7c391ba23 100644
--- a/src/sync/waitgroup_test.go
+++ b/src/sync/waitgroup_test.go
@@ -70,11 +70,8 @@ func TestWaitGroupMisuse(t *testing.T) {
func TestWaitGroupMisuse2(t *testing.T) {
knownRacy(t)
- if testing.Short() {
- t.Skip("skipping flaky test in short mode; see issue 11443")
- }
- if runtime.NumCPU() <= 2 {
- t.Skip("NumCPU<=2, skipping: this test requires parallelism")
+ if runtime.NumCPU() <= 4 {
+ t.Skip("NumCPU<=4, skipping: this test requires parallelism")
}
defer func() {
err := recover()
@@ -86,24 +83,37 @@ func TestWaitGroupMisuse2(t *testing.T) {
}()
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4))
done := make(chan interface{}, 2)
- // The detection is opportunistically, so we want it to panic
+ // The detection is opportunistic, so we want it to panic
// at least in one run out of a million.
for i := 0; i < 1e6; i++ {
var wg WaitGroup
+ var here uint32
wg.Add(1)
go func() {
defer func() {
done <- recover()
}()
+ atomic.AddUint32(&here, 1)
+ for atomic.LoadUint32(&here) != 3 {
+ // spin
+ }
wg.Wait()
}()
go func() {
defer func() {
done <- recover()
}()
+ atomic.AddUint32(&here, 1)
+ for atomic.LoadUint32(&here) != 3 {
+ // spin
+ }
wg.Add(1) // This is the bad guy.
wg.Done()
}()
+ atomic.AddUint32(&here, 1)
+ for atomic.LoadUint32(&here) != 3 {
+ // spin
+ }
wg.Done()
for j := 0; j < 2; j++ {
if err := <-done; err != nil {