diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-16 19:48:12 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-16 19:48:12 +0000 |
| commit | 174b3c8198444605aca33db9b077f36f7bc1c3fb (patch) | |
| tree | 298440f141c17a649a56379e9324db272d24acf9 | |
| parent | 17a36cc83980d278a8cab5132bf14de731b352ca (diff) | |
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 <noreply@anthropic.com>
| -rw-r--r-- | internal/executor/executor_test.go | 16 |
1 files changed, 13 insertions, 3 deletions
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") |
