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

Function TestLifecycler_ZonesCount

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

Source from the content-addressed store, hash-verified

442}
443
444func TestLifecycler_ZonesCount(t *testing.T) {
445 t.Parallel()
446
447 ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil)
448 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
449
450 var ringConfig Config
451 flagext.DefaultValues(&ringConfig)
452 ringConfig.KVStore.Mock = ringStore
453
454 events := []struct {
455 zone string
456 expectedZones int
457 }{
458 {"zone-a", 1},
459 {"zone-b", 2},
460 {"zone-a", 2},
461 {"zone-c", 3},
462 }
463
464 for idx, event := range events {
465 ctx := context.Background()
466
467 // Register an ingester to the ring.
468 cfg := testLifecyclerConfig(ringConfig, fmt.Sprintf("instance-%d", idx))
469 cfg.HeartbeatPeriod = 100 * time.Millisecond
470 cfg.JoinAfter = 100 * time.Millisecond
471 cfg.Zone = event.zone
472
473 lifecycler, err := NewLifecycler(cfg, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil)
474 require.NoError(t, err)
475 assert.Equal(t, 0, lifecycler.ZonesCount())
476
477 require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler))
478 defer services.StopAndAwaitTerminated(ctx, lifecycler) // nolint:errcheck
479
480 // Wait until joined.
481 test.Poll(t, time.Second, idx+1, func() interface{} {
482 return lifecycler.HealthyInstancesCount()
483 })
484
485 assert.Equal(t, event.expectedZones, lifecycler.ZonesCount())
486 }
487}
488
489func TestLifecycler_Zones(t *testing.T) {
490 t.Parallel()

Callers

nothing calls this directly

Calls 12

ZonesCountMethod · 0.95
HealthyInstancesCountMethod · 0.95
NewInMemoryClientFunction · 0.92
DefaultValuesFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
GetCodecFunction · 0.85
testLifecyclerConfigFunction · 0.85
NewLifecyclerFunction · 0.85
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected