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 <noreply@anthropic.com>

* agent: report last JobRequest error on dispatch timeout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Raja Subramanian
2026-10-14 13:27:55 +05:30
committed by GitHub
co-authored by Claude Opus 5.5
parent e5655ac202
commit 36ba8ad338
+6 -2
View File
@@ -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():