MCPcopy Create free account
hub / github.com/coder/coder / TestHeartbeats_Cleanup

Function TestHeartbeats_Cleanup

enterprise/tailnet/pgcoord_internal_test.go:39–70  ·  view source on GitHub ↗

TestHeartbeats_Cleanup tests the cleanup loop

(t *testing.T)

Source from the content-addressed store, hash-verified

37
38// TestHeartbeats_Cleanup tests the cleanup loop
39func TestHeartbeats_Cleanup(t *testing.T) {
40 t.Parallel()
41
42 ctrl := gomock.NewController(t)
43 mStore := dbmock.NewMockStore(ctrl)
44
45 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
46 defer cancel()
47 logger := testutil.Logger(t)
48
49 mStore.EXPECT().CleanTailnetCoordinators(gomock.Any()).Times(2).Return(nil)
50 mStore.EXPECT().CleanTailnetLostPeers(gomock.Any()).Times(2).Return(nil)
51 mStore.EXPECT().CleanTailnetTunnels(gomock.Any()).Times(2).Return(nil)
52
53 mClock := quartz.NewMock(t)
54 trap := mClock.Trap().TickerFunc("heartbeats", "cleanupLoop")
55 defer trap.Close()
56
57 uut := &heartbeats{
58 ctx: ctx,
59 logger: logger,
60 store: mStore,
61 clock: mClock,
62 }
63 uut.wg.Add(1)
64 go uut.cleanupLoop()
65
66 call := trap.MustWait(ctx)
67 call.MustRelease(ctx)
68 require.Equal(t, cleanupPeriod, call.Duration)
69 mClock.Advance(cleanupPeriod).MustWait(ctx)
70}
71
72// TestHeartbeats_recvBeat_resetSkew is a regression test for a bug where heartbeats from two
73// coordinators slightly skewed from one another could result in one coordinator failing to get

Callers

nothing calls this directly

Calls 10

EXPECTMethod · 0.95
cleanupLoopMethod · 0.95
NewMockStoreFunction · 0.92
LoggerFunction · 0.92
CleanTailnetLostPeersMethod · 0.65
CleanTailnetTunnelsMethod · 0.65
CloseMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected