From 174b3c8198444605aca33db9b077f36f7bc1c3fb Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Mon, 16 Mar 2026 19:48:12 +0000 Subject: fix: eliminate flaky race in TestPool_ActivePerAgent_DeletesZeroEntries The deferred activePerAgent cleanup in execute() runs after resultCh is sent, so a consumer reading Results() could observe the map entry before it was removed. Poll briefly (100ms max) instead of checking immediately. Co-Authored-By: Claude Sonnet 4.6 --- internal/executor/executor_test.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'internal/executor/executor_test.go') diff --git a/internal/executor/executor_test.go b/internal/executor/executor_test.go index 878a32d..d8a2b77 100644 --- a/internal/executor/executor_test.go +++ b/internal/executor/executor_test.go @@ -751,9 +751,19 @@ func TestPool_ActivePerAgent_DeletesZeroEntries(t *testing.T) { pool.Submit(context.Background(), tk) <-pool.Results() - pool.mu.Lock() - _, exists := pool.activePerAgent["claude"] - pool.mu.Unlock() + // The deferred cleanup in execute() runs after resultCh is sent, so poll + // briefly for the map entry to be removed rather than checking immediately. + var exists bool + deadline := time.Now().Add(100 * time.Millisecond) + for time.Now().Before(deadline) { + pool.mu.Lock() + _, exists = pool.activePerAgent["claude"] + pool.mu.Unlock() + if !exists { + break + } + time.Sleep(time.Millisecond) + } if exists { t.Error("activePerAgent should not have a zero-count entry for claude after task completes") -- cgit v1.2.3