Skip to content

Commit 9caaac2

Browse files
committed
sync: only check for successful PopHeads in long mode
In TestPoolDequeue it's surprisingly common for the queue to stay nearly empty the whole time and for a racing PopTail to happen in the window between the producer doing a PushHead and doing a PopHead. In short mode, there are only 100 PopTail attempts. On linux/amd64, it's not uncommon for this to fail 50% of the time. On linux/arm64, it's not uncommon for this to fail 100% of the time, causing the test to fail. This CL fixes this by only checking for a successful PopTail in long mode. Long mode makes 200,000 PopTail attempts, and has never been observed to fail. Fixes #31422. Change-Id: If464d55eb94fcb0b8d78fbc441d35be9f056a290 Reviewed-on: https://go-review.googlesource.com/c/go/+/183981 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent c19b3a6 commit 9caaac2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/sync/pool_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ func testPoolDequeue(t *testing.T, d PoolDequeue) {
236236
t.Errorf("expected have[%d] = 1, got %d", i, count)
237237
}
238238
}
239-
if nPopHead == 0 {
240-
// In theory it's possible in a valid schedule for
241-
// popHead to never succeed, but in practice it almost
242-
// always succeeds, so this is unlikely to flake.
239+
// Check that at least some PopHeads succeeded. We skip this
240+
// check in short mode because it's common enough that the
241+
// queue will stay nearly empty all the time and a PopTail
242+
// will happen during the window between every PushHead and
243+
// PopHead.
244+
if !testing.Short() && nPopHead == 0 {
243245
t.Errorf("popHead never succeeded")
244246
}
245247
}

0 commit comments

Comments
 (0)