From bc2d9b607b31b75439894a6b9b8eee1269e438e9 Mon Sep 17 00:00:00 2001 From: Hugo Dutka Date: Fri, 12 Jun 2026 17:47:20 +0200 Subject: [PATCH] fix(coderd/x/chatd): deflake TestRunner_StartsRealRequiresActionTimeoutTask (#26343) Addresses https://github.com/coder/internal/issues/1588#issuecomment-4692645760 --- coderd/x/chatd/tasks_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/coderd/x/chatd/tasks_test.go b/coderd/x/chatd/tasks_test.go index 6ca34a4b27..f844d1bb0b 100644 --- a/coderd/x/chatd/tasks_test.go +++ b/coderd/x/chatd/tasks_test.go @@ -890,13 +890,16 @@ func (f *taskTestFixture) publishChatUpdate(t *testing.T, chat database.Chat) { func (f *taskTestFixture) requireWatchEvent(t *testing.T, chatID uuid.UUID, kind codersdk.ChatWatchEventKind) { t.Helper() - events := f.pubsub.watchEvents(t) - for _, event := range events { - if event.Kind == kind && event.Chat.ID == chatID { - return + // Watch events are published after the corresponding database update + // commits, so poll instead of asserting on a single snapshot. + testutil.Eventually(testutil.Context(t, testutil.WaitLong), t, func(_ context.Context) bool { + for _, event := range f.pubsub.watchEvents(t) { + if event.Kind == kind && event.Chat.ID == chatID { + return true + } } - } - t.Fatalf("missing watch event kind=%s chat_id=%s events=%v", kind, chatID, events) + return false + }, testutil.IntervalFast) } func (f *taskTestFixture) requireNoWatchEvents(t *testing.T) {