chore(coderd): fix test flake in TestAgentWebsocketMonitor_SendPings (#11518)

This commit is contained in:
Cian Johnston
2024-01-10 08:45:46 +00:00
committed by GitHub
parent 5ed3c413cd
commit 5ecb0db4f2
+9 -2
View File
@@ -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)
}