From 6242917a16cc47c1e862d24131aa6ba1fb747c0f Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Tue, 9 Jan 2024 16:44:08 +0000 Subject: [PATCH] chore(coderd): fix test flake in TestAgentWebsocketMonitor_SendPings --- coderd/workspaceagentsrpc_internal_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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) }