From 36ba8ad338424d3854e07167c8143d17cea466a9 Mon Sep 17 00:00:00 2001 From: Raja Subramanian Date: Wed, 14 Oct 2026 13:27:55 +0530 Subject: [PATCH] agent: fix flaky TestAgent job dispatch (#5002) * agent: fix flaky TestAgent job dispatch Retry JobRequest until the worker subscribes the job topic, because registration is async and the topic is subscribed after the register response. Co-Authored-By: Claude Opus 5.5 * agent: report last JobRequest error on dispatch timeout Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- pkg/agent/agent_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/agent/agent_test.go b/pkg/agent/agent_test.go index 4ec83bc8f..fab7656df 100644 --- a/pkg/agent/agent_test.go +++ b/pkg/agent/agent_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/atomic" @@ -41,8 +42,11 @@ func TestAgent(t *testing.T) { Room: &livekit.Room{}, AgentName: testAgentName, } - _, err := client.JobRequest(context.Background(), testAgentName, agent.RoomAgentTopic, job) - require.NoError(t, err) + // registration is async and the job topic is subscribed after the register response, so retry until a worker is there + require.EventuallyWithT(t, func(c *assert.CollectT) { + _, err := client.JobRequest(context.Background(), testAgentName, agent.RoomAgentTopic, job) + assert.NoError(c, err) + }, 5*time.Second, 50*time.Millisecond) select { case a := <-jobAssignments.Events():