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

Function TestLifecycler_Zones

ring/lifecycler_test.go:489–743  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

487}
488
489func 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{

Callers

nothing calls this directly

Calls 15

ZonesCountMethod · 0.95
HealthyInstancesCountMethod · 0.95
ZonesMethod · 0.95
NewInMemoryClientFunction · 0.92
DefaultValuesFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
GetCodecFunction · 0.85
testLifecyclerConfigFunction · 0.85
WithHeartbeatPeriodFunction · 0.85
WithJoinAfterFunction · 0.85

Tested by

no test coverage detected