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

Function TestBasicLifecycler_TokensObservePeriod

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

Source from the content-addressed store, hash-verified

545}
546
547func TestBasicLifecycler_TokensObservePeriod(t *testing.T) {
548 ctx := context.Background()
549 cfg := prepareBasicLifecyclerConfig()
550 cfg.NumTokens = 5
551 cfg.TokensObservePeriod = time.Second
552
553 lifecycler, delegate, store, err := prepareBasicLifecycler(t, cfg)
554 require.NoError(t, err)
555 defer services.StopAndAwaitTerminated(ctx, lifecycler) //nolint:errcheck
556
557 delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (InstanceState, Tokens) {
558 return ACTIVE, Tokens{1, 2, 3, 4, 5}
559 }
560
561 require.NoError(t, lifecycler.StartAsync(ctx))
562
563 // While the lifecycler is starting we poll the ring. As soon as the instance
564 // is registered, we remove some tokens to simulate how gossip memberlist
565 // reconciliation works in case of clashing tokens.
566 test.Poll(t, time.Second, true, func() interface{} {
567 // Ensure the instance has been registered in the ring.
568 desc, ok := getInstanceFromStore(t, store, testInstanceID)
569 if !ok {
570 return false
571 }
572
573 // Remove some tokens.
574 return store.CAS(ctx, testRingKey, func(in interface{}) (out interface{}, retry bool, err error) {
575 ringDesc := GetOrCreateRingDesc(in)
576 ringDesc.AddIngester(testInstanceID, desc.Addr, desc.Zone, Tokens{4, 5}, desc.State, time.Now(), false, time.Time{}, nil)
577 return ringDesc, true, nil
578 }) == nil
579 })
580
581 require.NoError(t, lifecycler.AwaitRunning(ctx))
582 assert.Subset(t, lifecycler.GetTokens(), Tokens{4, 5})
583 assert.NotContains(t, lifecycler.GetTokens(), uint32(1))
584 assert.NotContains(t, lifecycler.GetTokens(), uint32(2))
585 assert.NotContains(t, lifecycler.GetTokens(), uint32(3))
586}
587
588func TestBasicLifecycler_updateInstance_ShouldAddInstanceToTheRingIfDoesNotExistEvenIfNotChanged(t *testing.T) {
589 for _, readOnly := range []bool{false, true} {

Callers

nothing calls this directly

Calls 11

StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
prepareBasicLifecyclerFunction · 0.85
getInstanceFromStoreFunction · 0.85
GetOrCreateRingDescFunction · 0.85
AddIngesterMethod · 0.80
StartAsyncMethod · 0.65
CASMethod · 0.65
AwaitRunningMethod · 0.65
GetTokensMethod · 0.45

Tested by

no test coverage detected