MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestRulerShutdown

Function TestRulerShutdown

pkg/ruler/lifecycle_test.go:20–51  ·  view source on GitHub ↗

TestRulerShutdown tests shutting down ruler unregisters correctly

(t *testing.T)

Source from the content-addressed store, hash-verified

18
19// TestRulerShutdown tests shutting down ruler unregisters correctly
20func TestRulerShutdown(t *testing.T) {
21 ctx := context.Background()
22
23 store := newMockRuleStore(mockRules, nil)
24 config := defaultRulerConfig(t)
25
26 r, _ := buildRuler(t, config, nil, store, nil)
27
28 r.cfg.EnableSharding = true
29 ringStore, closer := consul.NewInMemoryClient(ring.GetCodec(), log.NewNopLogger(), nil)
30 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
31
32 err := enableSharding(r, ringStore)
33 require.NoError(t, err)
34
35 require.NoError(t, services.StartAndAwaitRunning(ctx, r))
36 defer services.StopAndAwaitTerminated(ctx, r) //nolint:errcheck
37
38 // Wait until the tokens are registered in the ring
39 test.Poll(t, 100*time.Millisecond, config.Ring.NumTokens, func() any {
40 return numTokens(ringStore, "localhost", ringKey)
41 })
42
43 require.Equal(t, ring.ACTIVE, r.lifecycler.GetState())
44
45 require.NoError(t, services.StopAndAwaitTerminated(context.Background(), r))
46
47 // Wait until the tokens are unregistered from the ring
48 test.Poll(t, 100*time.Millisecond, 0, func() any {
49 return numTokens(ringStore, "localhost", ringKey)
50 })
51}
52
53func TestRuler_RingLifecyclerShouldAutoForgetUnhealthyInstances(t *testing.T) {
54 const unhealthyInstanceID = "unhealthy-id"

Callers

nothing calls this directly

Calls 13

NewInMemoryClientFunction · 0.92
GetCodecFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
PollFunction · 0.92
newMockRuleStoreFunction · 0.85
defaultRulerConfigFunction · 0.85
buildRulerFunction · 0.85
enableShardingFunction · 0.85
numTokensFunction · 0.70
CloseMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected