]> Cypherpunks repositories - gostls13.git/commitdiff
sync: use blockUntilCleanupQueueEmpty instead of busy-looping in tests
authorMichael Anthony Knyszek <mknyszek@google.com>
Sat, 10 May 2025 16:14:25 +0000 (16:14 +0000)
committerMichael Knyszek <mknyszek@google.com>
Thu, 15 May 2025 03:42:54 +0000 (20:42 -0700)
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>

src/sync/pool_test.go

index 286dcacf3ecc84366d0b780e8c85a25d0506c7ef..7f60ed70265bdcbcc8579eaea6106af8733340db 100644 (file)
@@ -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)
+               }
        }
 }