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

Function TestBasicLifecycler_HeartbeatWhileStopping

ring/basic_lifecycler_test.go:378–414  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

376}
377
378func TestBasicLifecycler_HeartbeatWhileStopping(t *testing.T) {
379 ctx := context.Background()
380 cfg := prepareBasicLifecyclerConfig()
381 cfg.HeartbeatPeriod = 10 * time.Millisecond
382
383 lifecycler, delegate, store, err := prepareBasicLifecycler(t, cfg)
384 require.NoError(t, err)
385 require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler))
386
387 onStoppingCalled := false
388
389 delegate.onStopping = func(_ *BasicLifecycler) {
390 // Since the hearbeat timestamp is in seconds we would have to wait 1s before we can assert
391 // on it being changed, regardless the heartbeat period. To speed up this test, we're going
392 // to reset the timestamp to 0 and then assert it has been updated.
393 require.NoError(t, store.CAS(ctx, testRingKey, func(in interface{}) (out interface{}, retry bool, err error) {
394 ringDesc := GetOrCreateRingDesc(in)
395 instanceDesc := ringDesc.Ingesters[testInstanceID]
396 instanceDesc.Timestamp = 0
397 ringDesc.Ingesters[testInstanceID] = instanceDesc
398 return ringDesc, true, nil
399 }))
400
401 // Wait until the timestamp has been updated.
402 test.Poll(t, time.Second, true, func() interface{} {
403 desc, _ := getInstanceFromStore(t, store, testInstanceID)
404 currTimestamp := desc.GetTimestamp()
405
406 return currTimestamp != 0
407 })
408
409 onStoppingCalled = true
410 }
411
412 assert.NoError(t, services.StopAndAwaitTerminated(ctx, lifecycler))
413 assert.True(t, onStoppingCalled)
414}
415
416func TestBasicLifecycler_HeartbeatAfterBackendReset(t *testing.T) {
417 ctx := context.Background()

Callers

nothing calls this directly

Calls 9

StartAndAwaitRunningFunction · 0.92
PollFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
prepareBasicLifecyclerFunction · 0.85
GetOrCreateRingDescFunction · 0.85
getInstanceFromStoreFunction · 0.85
GetTimestampMethod · 0.80
CASMethod · 0.65

Tested by

no test coverage detected