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

Function TestCheckReady_NoRingInKVStore

ring/lifecycler_test.go:1249–1280  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
1249func 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
1282func TestCheckReady_MinReadyDuration(t *testing.T) {
1283 t.Parallel()

Callers

nothing calls this directly

Calls 11

setTokensMethod · 0.95
CheckReadyMethod · 0.95
DefaultValuesFunction · 0.92
StartAndAwaitRunningFunction · 0.92
StopAndAwaitTerminatedFunction · 0.92
testLifecyclerConfigFunction · 0.85
NewLifecyclerFunction · 0.85
NewFunction · 0.70
StartAsyncMethod · 0.65
AwaitTerminatedMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected