mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
3ea94ae446
commit
a197a471b9
|
|
@ -104,7 +104,6 @@ func TestPoolRelease(t *testing.T) {
|
|||
func testPool(t *testing.T, drain bool) {
|
||||
var p Pool
|
||||
const N = 100
|
||||
loop:
|
||||
for try := 0; try < 3; try++ {
|
||||
if try == 1 && testing.Short() {
|
||||
break
|
||||
|
|
@ -119,16 +118,19 @@ loop:
|
|||
for i := 0; i < N; i++ {
|
||||
p.Get()
|
||||
}
|
||||
}
|
||||
for i := 0; i < 5; i++ {
|
||||
} else {
|
||||
// Run an extra GC cycles to drop items from the pool.
|
||||
runtime.GC()
|
||||
time.Sleep(time.Duration(i*100+10) * time.Millisecond)
|
||||
// 1 pointer can remain on stack or elsewhere
|
||||
if cln1 = atomic.LoadUint32(&cln); cln1 >= N-1 {
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
t.Fatalf("only %v out of %v resources are cleaned up on try %v", cln1, N, try)
|
||||
|
||||
// Run a GC and wait for all the cleanups to run.
|
||||
runtime.GC()
|
||||
runtime_blockUntilEmptyCleanupQueue(int64(5 * time.Second))
|
||||
|
||||
// 1 pointer can remain on stack or elsewhere
|
||||
if cln1 = atomic.LoadUint32(&cln); cln1 < N-1 {
|
||||
t.Fatalf("only %v out of %v resources are cleaned up on try %v", cln1, N, try)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue