From 281d739baef79f8aeba1a7f3467ed0f666421593 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Tue, 10 Nov 2026 06:25:43 +0300 Subject: [PATCH] test(pool): wait for kill in TestRunGCReapsThenStops reap deletes the bot from the map under the lock and kills it after unlocking, so the test could observe an empty map before kill ran. --- pool/pool_internal_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pool/pool_internal_test.go b/pool/pool_internal_test.go index 7a208c5..9f87788 100644 --- a/pool/pool_internal_test.go +++ b/pool/pool_internal_test.go @@ -144,7 +144,9 @@ func TestRunGCReapsThenStops(t *testing.T) { go func() { p.RunGC(ctx); close(done) }() - // Wait for the idle bot to be reaped. + // Wait for the idle bot to be reaped and killed. reap removes the bot from + // the map under the lock and kills it after unlocking, so both must be + // awaited. deadline := time.After(2 * time.Second) for { @@ -153,21 +155,17 @@ func TestRunGCReapsThenStops(t *testing.T) { n := len(p.bots) p.mu.Unlock() - if n == 0 { + if n == 0 && killed.Load() { break } select { case <-deadline: - t.Fatal("idle bot was not reaped") + t.Fatalf("idle bot was not reaped (bots=%d, killed=%v)", n, killed.Load()) case <-time.After(5 * time.Millisecond): } } - if !killed.Load() { - t.Fatal("reaped bot should be killed") - } - cancel() select {