(t *testing.T)
| 487 | } |
| 488 | |
| 489 | func TestLifecycler_Zones(t *testing.T) { |
| 490 | t.Parallel() |
| 491 | |
| 492 | t.Run("instances joining different zones", func(t *testing.T) { |
| 493 | ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) |
| 494 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 495 | |
| 496 | ctx := context.Background() |
| 497 | var ringConfig Config |
| 498 | flagext.DefaultValues(&ringConfig) |
| 499 | ringConfig.KVStore.Mock = ringStore |
| 500 | |
| 501 | events := []struct { |
| 502 | zone string |
| 503 | expectedZones []string |
| 504 | }{ |
| 505 | {"zone-a", []string{"zone-a"}}, |
| 506 | {"zone-b", []string{"zone-a", "zone-b"}}, |
| 507 | {"zone-a", []string{"zone-a", "zone-b"}}, |
| 508 | {"zone-c", []string{"zone-a", "zone-b", "zone-c"}}, |
| 509 | } |
| 510 | |
| 511 | for idx, event := range events { |
| 512 | // Register an ingester to the ring. |
| 513 | cfg := testLifecyclerConfig( |
| 514 | ringConfig, |
| 515 | fmt.Sprintf("instance-%d", idx), |
| 516 | WithHeartbeatPeriod(100*time.Millisecond), |
| 517 | WithJoinAfter(100*time.Millisecond), |
| 518 | WithZone(event.zone), |
| 519 | ) |
| 520 | |
| 521 | lifecycler, err := NewLifecycler(cfg, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil) |
| 522 | require.NoError(t, err) |
| 523 | assert.Equal(t, 0, lifecycler.ZonesCount()) |
| 524 | |
| 525 | require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) |
| 526 | defer services.StopAndAwaitTerminated(ctx, lifecycler) // nolint:errcheck |
| 527 | |
| 528 | // Wait until joined. |
| 529 | test.Poll(t, time.Second, idx+1, func() interface{} { |
| 530 | return lifecycler.HealthyInstancesCount() |
| 531 | }) |
| 532 | |
| 533 | assert.Equal(t, event.expectedZones, lifecycler.Zones()) |
| 534 | } |
| 535 | }) |
| 536 | |
| 537 | t.Run("instances leaving zones", func(t *testing.T) { |
| 538 | ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) |
| 539 | t.Cleanup(func() { assert.NoError(t, closer.Close()) }) |
| 540 | |
| 541 | var ringConfig Config |
| 542 | flagext.DefaultValues(&ringConfig) |
| 543 | ringConfig.KVStore.Mock = ringStore |
| 544 | ctx := context.Background() |
| 545 | |
| 546 | defaultOpts := []TestLifecyclerConfigOption{ |
nothing calls this directly
no test coverage detected