(t *testing.T)
| 545 | } |
| 546 | |
| 547 | func 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 | |
| 588 | func TestBasicLifecycler_updateInstance_ShouldAddInstanceToTheRingIfDoesNotExistEvenIfNotChanged(t *testing.T) { |
| 589 | for _, readOnly := range []bool{false, true} { |
nothing calls this directly
no test coverage detected