TestRulerShutdown tests shutting down ruler unregisters correctly
(t *testing.T)
| 18 | |
| 19 | // TestRulerShutdown tests shutting down ruler unregisters correctly |
| 20 | func 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 | |
| 53 | func TestRuler_RingLifecyclerShouldAutoForgetUnhealthyInstances(t *testing.T) { |
| 54 | const unhealthyInstanceID = "unhealthy-id" |
nothing calls this directly
no test coverage detected