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

Function TestBasicLifecycler_ChangeState

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

Source from the content-addressed store, hash-verified

459}
460
461func TestBasicLifecycler_ChangeState(t *testing.T) {
462 ctx := context.Background()
463 cfg := prepareBasicLifecyclerConfig()
464 lifecycler, delegate, store, err := prepareBasicLifecycler(t, cfg)
465 require.NoError(t, err)
466 defer services.StopAndAwaitTerminated(ctx, lifecycler) //nolint:errcheck
467
468 delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (InstanceState, Tokens) {
469 return JOINING, Tokens{1, 2, 3, 4, 5}
470 }
471
472 require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler))
473 assert.Equal(t, JOINING, lifecycler.GetState())
474
475 for _, state := range []InstanceState{ACTIVE, LEAVING} {
476 assert.NoError(t, lifecycler.ChangeState(ctx, state))
477 assert.Equal(t, state, lifecycler.GetState())
478
479 // Assert on the instance state read from the ring.
480 desc, ok := getInstanceFromStore(t, store, testInstanceID)
481 assert.True(t, ok)
482 assert.Equal(t, state, desc.GetState())
483 }
484}
485
486func TestBasicLifecycler_ChangeReadOnlyState(t *testing.T) {
487 ctx := context.Background()

Callers

nothing calls this directly

Calls 8

StopAndAwaitTerminatedFunction · 0.92
StartAndAwaitRunningFunction · 0.92
prepareBasicLifecyclerFunction · 0.85
getInstanceFromStoreFunction · 0.85
EqualMethod · 0.45
GetStateMethod · 0.45
ChangeStateMethod · 0.45

Tested by

no test coverage detected