From 14efafc8a2ee933800d952a7296c6a6c6e7a4fef Mon Sep 17 00:00:00 2001 From: Lakshman Patel Date: Sun, 2 Aug 2026 23:03:39 +0530 Subject: [PATCH] test(engine): de-flake bg pool Stop assertion in CI --- internal/engine/agent/background_agent_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/engine/agent/background_agent_test.go b/internal/engine/agent/background_agent_test.go index 5f79efe6..2c694342 100644 --- a/internal/engine/agent/background_agent_test.go +++ b/internal/engine/agent/background_agent_test.go @@ -51,8 +51,10 @@ func TestBackgroundAgentPool_StopCancelsInFlight(t *testing.T) { pool.Stop() + // The registry only drains a task once its spawn fn returns, so poll + // until the cancellation is observed AND the task has exited. deadline = time.Now().Add(2 * time.Second) - for !cancelled.Load() && time.Now().Before(deadline) { + for (!cancelled.Load() || pool.PendingCount() != 0) && time.Now().Before(deadline) { time.Sleep(time.Millisecond) } if !cancelled.Load() {