Ensure a check ready returns error when consul returns a nil key and the ingester already holds keys. This happens if the ring key gets deleted
(t *testing.T)
| 1247 | |
| 1248 | // Ensure a check ready returns error when consul returns a nil key and the ingester already holds keys. This happens if the ring key gets deleted |
| 1249 | func TestCheckReady_NoRingInKVStore(t *testing.T) { |
| 1250 | t.Parallel() |
| 1251 | |
| 1252 | ctx := context.Background() |
| 1253 | |
| 1254 | var ringConfig Config |
| 1255 | flagext.DefaultValues(&ringConfig) |
| 1256 | ringConfig.KVStore.Mock = &MockClient{} |
| 1257 | |
| 1258 | r, err := New(ringConfig, "ingester", ringKey, log.NewNopLogger(), nil) |
| 1259 | require.NoError(t, err) |
| 1260 | require.NoError(t, r.StartAsync(ctx)) |
| 1261 | // This is very atypical, but if we used AwaitRunning, that would fail, because of how quickly service terminates ... |
| 1262 | // by the time we check for Running state, it is already terminated, because mock ring has no WatchFunc, so it |
| 1263 | // will just exit. |
| 1264 | require.NoError(t, r.AwaitTerminated(ctx)) |
| 1265 | |
| 1266 | cfg := testLifecyclerConfig(ringConfig, "ring1") |
| 1267 | cfg.MinReadyDuration = 1 * time.Nanosecond |
| 1268 | l1, err := NewLifecycler(cfg, &nopFlushTransferer{}, "ingester", ringKey, true, log.NewNopLogger(), nil) |
| 1269 | require.NoError(t, err) |
| 1270 | require.NoError(t, services.StartAndAwaitRunning(ctx, l1)) |
| 1271 | t.Cleanup(func() { |
| 1272 | require.NoError(t, services.StopAndAwaitTerminated(ctx, l1)) |
| 1273 | }) |
| 1274 | |
| 1275 | l1.setTokens([]uint32{1}) |
| 1276 | |
| 1277 | err = l1.CheckReady(context.Background()) |
| 1278 | require.Error(t, err) |
| 1279 | assert.Contains(t, err.Error(), "no ring returned from the KV store") |
| 1280 | } |
| 1281 | |
| 1282 | func TestCheckReady_MinReadyDuration(t *testing.T) { |
| 1283 | t.Parallel() |
nothing calls this directly
no test coverage detected