Skip to content

Commit a197a47

Browse files
committed
sync: use blockUntilCleanupQueueEmpty instead of busy-looping in tests
testPool currently does the old-style busy loop to wait until cleanups have executed. Clean this up by using the linkname'd blockUntilCleanupQueueEmpty. For #73642. Change-Id: Ie0c2614db858a984f25b33a805dc52948069eb52 Reviewed-on: https://go-review.googlesource.com/c/go/+/671675 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 3ea94ae commit a197a47

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/sync/pool_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ func TestPoolRelease(t *testing.T) {
104104
func testPool(t *testing.T, drain bool) {
105105
var p Pool
106106
const N = 100
107-
loop:
108107
for try := 0; try < 3; try++ {
109108
if try == 1 && testing.Short() {
110109
break
@@ -119,16 +118,19 @@ loop:
119118
for i := 0; i < N; i++ {
120119
p.Get()
121120
}
122-
}
123-
for i := 0; i < 5; i++ {
121+
} else {
122+
// Run an extra GC cycles to drop items from the pool.
124123
runtime.GC()
125-
time.Sleep(time.Duration(i*100+10) * time.Millisecond)
126-
// 1 pointer can remain on stack or elsewhere
127-
if cln1 = atomic.LoadUint32(&cln); cln1 >= N-1 {
128-
continue loop
129-
}
130124
}
131-
t.Fatalf("only %v out of %v resources are cleaned up on try %v", cln1, N, try)
125+
126+
// Run a GC and wait for all the cleanups to run.
127+
runtime.GC()
128+
runtime_blockUntilEmptyCleanupQueue(int64(5 * time.Second))
129+
130+
// 1 pointer can remain on stack or elsewhere
131+
if cln1 = atomic.LoadUint32(&cln); cln1 < N-1 {
132+
t.Fatalf("only %v out of %v resources are cleaned up on try %v", cln1, N, try)
133+
}
132134
}
133135
}
134136

0 commit comments

Comments
 (0)