aboutsummaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2019-06-26 11:11:45 -0400
committerAustin Clements <austin@google.com>2019-06-26 19:48:39 +0000
commit93c05627f9e542476d8f88e2e472082d526689ff (patch)
tree871808878eaff54730468f860305637e9c246bac /src/sync
parent4b41f7f8188ce8f711cacd3097a2cb02af5c333c (diff)
downloadgo-93c05627f9e542476d8f88e2e472082d526689ff.tar.gz
go-93c05627f9e542476d8f88e2e472082d526689ff.zip
sync: fix pool wrap-around test
TestPoolDequeue in long mode does a little more than 1<<21 pushes. This was originally because the head and tail indexes were 21 bits and the intent was to test wrap-around behavior. However, in the final version they were both 32 bits, so the test no longer tested wrap-around. It would take too long to reach 32-bit wrap around in a test, so instead we initialize the poolDequeue with indexes that are already nearly at their limit. This keeps the knowledge of the maximum index in one place, and lets us test wrap-around even in short mode. Change-Id: Ib9b8d85b6d9b5be235849c2b32e81c809e806579 Reviewed-on: https://go-review.googlesource.com/c/go/+/183979 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/export_test.go6
-rw-r--r--src/sync/pool_test.go4
2 files changed, 6 insertions, 4 deletions
diff --git a/src/sync/export_test.go b/src/sync/export_test.go
index 10d3599f47..ffbe567464 100644
--- a/src/sync/export_test.go
+++ b/src/sync/export_test.go
@@ -18,9 +18,13 @@ type PoolDequeue interface {
}
func NewPoolDequeue(n int) PoolDequeue {
- return &poolDequeue{
+ d := &poolDequeue{
vals: make([]eface, n),
}
+ // For testing purposes, set the head and tail indexes close
+ // to wrapping around.
+ d.headTail = d.pack(1<<dequeueBits-500, 1<<dequeueBits-500)
+ return d
}
func (d *poolDequeue) PushHead(val interface{}) bool {
diff --git a/src/sync/pool_test.go b/src/sync/pool_test.go
index ff1174cc15..090f1a8c6a 100644
--- a/src/sync/pool_test.go
+++ b/src/sync/pool_test.go
@@ -173,9 +173,7 @@ func TestPoolChain(t *testing.T) {
func testPoolDequeue(t *testing.T, d PoolDequeue) {
const P = 10
- // In long mode, do enough pushes to wrap around the 21-bit
- // indexes.
- N := 1<<21 + 1000
+ var N int = 2e6
if testing.Short() {
N = 1e3
}