MCPcopy
hub / github.com/grafana/dskit / TestBasicLifecycler_HeartbeatWhileRunning

Function TestBasicLifecycler_HeartbeatWhileRunning

ring/basic_lifecycler_test.go:356–376  ·  ring/basic_lifecycler_test.go::TestBasicLifecycler_HeartbeatWhileRunning
(t *testing.T)

Source from the content-addressed store, hash-verified

354}
355
356func TestBasicLifecycler_HeartbeatWhileRunning(t *testing.T) {
357 ctx := context.Background()
358 cfg := prepareBasicLifecyclerConfig()
359 cfg.HeartbeatPeriod = 10 * time.Millisecond
360
361 lifecycler, _, store, err := prepareBasicLifecycler(t, cfg)
362 require.NoError(t, err)
363 defer services.StopAndAwaitTerminated(ctx, lifecycler) //nolint:errcheck
364 require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler))
365
366 // Get the initial timestamp so that we can then assert on the timestamp updated.
367 desc, _ := getInstanceFromStore(t, store, testInstanceID)
368 initialTimestamp := desc.GetTimestamp()
369
370 assert.Eventually(t, func() bool {
371 desc, _ := getInstanceFromStore(t, store, testInstanceID)
372 return desc.GetTimestamp() > initialTimestamp
373 }, 2*time.Second, 10*time.Millisecond, "expected timestamp to be updated")
374
375 assert.Greater(t, testutil.ToFloat64(lifecycler.metrics.heartbeats), float64(0))
376}
377
378func TestBasicLifecycler_HeartbeatWhileStopping(t *testing.T) {
379 ctx := context.Background()

Callers

nothing calls this directly

Calls 6

StopAndAwaitTerminatedFunction · 0.92
StartAndAwaitRunningFunction · 0.92
prepareBasicLifecyclerFunction · 0.85
getInstanceFromStoreFunction · 0.85
GetTimestampMethod · 0.80

Tested by

no test coverage detected