From a197a471b9c67af4881e0d9c48e4bd3cff4992c2 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Sat, 10 May 2025 16:14:25 +0000 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI --- src/sync/pool_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/sync/pool_test.go b/src/sync/pool_test.go index 286dcacf3e..7f60ed7026 100644 --- a/src/sync/pool_test.go +++ b/src/sync/pool_test.go @@ -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) + } } } -- 2.51.0