From f2904726a58178303938ffce2bb040beae5a4c58 Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Fri, 26 Sep 2025 09:24:11 +0400 Subject: [PATCH] test: wait for completion before asserting in TestAgentConnectionMonitor_BuildOutdated (#19959) follow on to #19836 fixes https://github.com/coder/internal/issues/970 Same issue, different (adjacent) test. --- coderd/workspaceagentsrpc_internal_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/coderd/workspaceagentsrpc_internal_test.go b/coderd/workspaceagentsrpc_internal_test.go index d44a666979..5c254b41fe 100644 --- a/coderd/workspaceagentsrpc_internal_test.go +++ b/coderd/workspaceagentsrpc_internal_test.go @@ -215,14 +215,20 @@ func TestAgentConnectionMonitor_BuildOutdated(t *testing.T) { AnyTimes(). Return(database.WorkspaceBuild{ID: uuid.New()}, nil) - go uut.monitor(ctx) + done := make(chan struct{}) + go func() { + uut.monitor(ctx) + close(done) + }() fConn.requireEventuallyClosed(t, websocket.StatusGoingAway, "build is outdated") fUpdater.requireEventuallySomeUpdates(t, build.WorkspaceID) + _ = testutil.TryReceive(ctx, t, done) // ensure monitor() exits before mDB assertions are checked. } func TestAgentConnectionMonitor_SendPings(t *testing.T) { t.Parallel() - ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) + testCtx := testutil.Context(t, testutil.WaitShort) + ctx, cancel := context.WithCancel(testCtx) t.Cleanup(cancel) fConn := &fakePingerCloser{} uut := &agentConnectionMonitor{ @@ -236,7 +242,7 @@ func TestAgentConnectionMonitor_SendPings(t *testing.T) { }() fConn.requireEventuallyHasPing(t) cancel() - <-done + _ = testutil.TryReceive(testCtx, t, done) lastPing := uut.lastPing.Load() require.NotNil(t, lastPing) }