From d0a51e17529f4fcb4e0a24d3439d9318347ca4ea Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Thu, 5 Mar 2026 09:42:34 +0000 Subject: [PATCH] fix: use testutil.Eventually in chatd interrupt test (#22653) Follow-up to #22630. Addresses [review feedback](https://github.com/coder/coder/pull/22630#pullrequestreview-2953419963) that was missed due to auto-merge. ## Changes Replaces three `require.Eventually` calls with `testutil.Eventually` in `TestInterruptChatDoesNotSendWebPushNotification`, linking the condition to the existing test context (`ctx`) created on line 1194. This ensures the test respects context cancellation instead of using a standalone timeout/tick pattern. --- coderd/chatd/chatd_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/coderd/chatd/chatd_test.go b/coderd/chatd/chatd_test.go index de603b1a3e..9b7d9ef2a9 100644 --- a/coderd/chatd/chatd_test.go +++ b/coderd/chatd/chatd_test.go @@ -1268,35 +1268,35 @@ func TestInterruptChatDoesNotSendWebPushNotification(t *testing.T) { require.NoError(t, err) // Wait for the chat to be picked up and start streaming. - require.Eventually(t, func() bool { + testutil.Eventually(ctx, t, func(ctx context.Context) bool { fromDB, dbErr := db.GetChatByID(ctx, chat.ID) if dbErr != nil { return false } return fromDB.Status == database.ChatStatusRunning && fromDB.WorkerID.Valid - }, testutil.WaitMedium, testutil.IntervalFast) + }, testutil.IntervalFast) - require.Eventually(t, func() bool { + testutil.Eventually(ctx, t, func(ctx context.Context) bool { select { case <-streamStarted: return true default: return false } - }, testutil.WaitMedium, testutil.IntervalFast) + }, testutil.IntervalFast) // Interrupt the chat. updated := server.InterruptChat(ctx, chat) require.Equal(t, database.ChatStatusWaiting, updated.Status) // Wait for the chat to finish processing and return to waiting. - require.Eventually(t, func() bool { + testutil.Eventually(ctx, t, func(ctx context.Context) bool { fromDB, dbErr := db.GetChatByID(ctx, chat.ID) if dbErr != nil { return false } return fromDB.Status == database.ChatStatusWaiting && !fromDB.WorkerID.Valid - }, testutil.WaitMedium, testutil.IntervalFast) + }, testutil.IntervalFast) // Verify no web push notification was dispatched. require.Equal(t, int32(0), mockPush.dispatchCount.Load(),