aboutsummaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2019-06-26 13:20:05 -0400
committerAustin Clements <austin@google.com>2019-06-26 19:48:40 +0000
commitc19b3a60da360a4e02b18dcb3430ec3485a0a831 (patch)
tree8ff451d5cebe3680070d2d1d86efa92449d39b2d /src/sync
parent93c05627f9e542476d8f88e2e472082d526689ff (diff)
downloadgo-c19b3a60da360a4e02b18dcb3430ec3485a0a831.tar.gz
go-c19b3a60da360a4e02b18dcb3430ec3485a0a831.zip
sync: make TestPoolDequeue termination condition more robust
TestPoolDequeue creates P-1 consumer goroutines and 1 producer goroutine. Currently, if a consumer goroutine pops the last value from the dequeue, it sets a flag that stops all consumers, but the producer also periodically pops from the dequeue and doesn't set this flag. Hence, if the producer were to pop the last element, the consumers will continue to run and the test won't terminate. This CL fixes this by also setting the termination flag in the producer. I believe it's impossible for this to happen right now because the producer only pops after pushing an element for which j%10==0 and the last element is either 999 or 1999999, which means it should never try to pop after pushing the last element. However, we shouldn't depend on this reasoning. Change-Id: Icd2bc8d7cb9a79ebfcec99e367c8a2ba76e027d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/183980 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/sync')
-rw-r--r--src/sync/pool_test.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/sync/pool_test.go b/src/sync/pool_test.go
index 090f1a8c6a..814c4a6812 100644
--- a/src/sync/pool_test.go
+++ b/src/sync/pool_test.go
@@ -180,6 +180,12 @@ func testPoolDequeue(t *testing.T, d PoolDequeue) {
have := make([]int32, N)
var stop int32
var wg WaitGroup
+ record := func(val int) {
+ atomic.AddInt32(&have[val], 1)
+ if val == N-1 {
+ atomic.StoreInt32(&stop, 1)
+ }
+ }
// Start P-1 consumers.
for i := 1; i < P; i++ {
@@ -190,10 +196,7 @@ func testPoolDequeue(t *testing.T, d PoolDequeue) {
val, ok := d.PopTail()
if ok {
fail = 0
- atomic.AddInt32(&have[val.(int)], 1)
- if val.(int) == N-1 {
- atomic.StoreInt32(&stop, 1)
- }
+ record(val.(int))
} else {
// Speed up the test by
// allowing the pusher to run.
@@ -219,7 +222,7 @@ func testPoolDequeue(t *testing.T, d PoolDequeue) {
val, ok := d.PopHead()
if ok {
nPopHead++
- atomic.AddInt32(&have[val.(int)], 1)
+ record(val.(int))
}
}
}