diff --git a/coderd/workspaceagentsrpc_internal_test.go b/coderd/workspaceagentsrpc_internal_test.go index b8e6eb381c7b3..834de4807d9be 100644 --- a/coderd/workspaceagentsrpc_internal_test.go +++ b/coderd/workspaceagentsrpc_internal_test.go @@ -219,14 +219,21 @@ func TestAgentWebsocketMonitor_BuildOutdated(t *testing.T) { func TestAgentWebsocketMonitor_SendPings(t *testing.T) { t.Parallel() - ctx := testutil.Context(t, testutil.WaitShort) + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort) + t.Cleanup(cancel) fConn := &fakePingerCloser{} uut := &agentWebsocketMonitor{ pingPeriod: testutil.IntervalFast, conn: fConn, } - go uut.sendPings(ctx) + done := make(chan struct{}) + go func() { + uut.sendPings(ctx) + close(done) + }() fConn.requireEventuallyHasPing(t) + cancel() + <-done lastPing := uut.lastPing.Load() require.NotNil(t, lastPing) }