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

Function TestCheckReady_CheckRingHealth

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

Source from the content-addressed store, hash-verified

1341}
1342
1343func TestCheckReady_CheckRingHealth(t *testing.T) {
1344 t.Parallel()
1345
1346 tests := map[string]struct {
1347 checkRingHealthEnabled bool
1348 firstJoinAfter time.Duration
1349 secondJoinAfter time.Duration
1350 expectedFirstMinReady time.Duration
1351 expectedFirstMaxReady time.Duration
1352 }{
1353 "should wait until the self instance is ACTIVE and healthy in the ring when 'check ring health' is disabled": {
1354 checkRingHealthEnabled: false,
1355 firstJoinAfter: time.Second,
1356 secondJoinAfter: 3 * time.Second,
1357 expectedFirstMinReady: time.Second,
1358 expectedFirstMaxReady: 2 * time.Second,
1359 },
1360 "should wait until all instances are ACTIVE and healthy in the ring when 'check ring health' is enabled": {
1361 checkRingHealthEnabled: true,
1362 firstJoinAfter: time.Second,
1363 secondJoinAfter: 3 * time.Second,
1364 expectedFirstMinReady: 3 * time.Second,
1365 expectedFirstMaxReady: 4 * time.Second,
1366 },
1367 }
1368
1369 for testName, testData := range tests {
1370 testData := testData
1371
1372 t.Run(testName, func(t *testing.T) {
1373 t.Parallel()
1374
1375 ctx := context.Background()
1376
1377 ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil)
1378 t.Cleanup(func() { assert.NoError(t, closer.Close()) })
1379
1380 var ringConfig Config
1381 flagext.DefaultValues(&ringConfig)
1382 ringConfig.KVStore.Mock = ringStore
1383
1384 // Create lifecycler #1.
1385 cfg := testLifecyclerConfig(ringConfig, "instance-1")
1386 cfg.ReadinessCheckRingHealth = testData.checkRingHealthEnabled
1387 cfg.MinReadyDuration = 0
1388 cfg.JoinAfter = testData.firstJoinAfter
1389
1390 l1, err := NewLifecycler(cfg, &nopFlushTransferer{}, "ring", ringKey, true, log.NewNopLogger(), nil)
1391 require.NoError(t, err)
1392 require.NoError(t, services.StartAndAwaitRunning(ctx, l1))
1393 t.Cleanup(func() {
1394 require.NoError(t, services.StopAndAwaitTerminated(ctx, l1))
1395 })
1396
1397 // Create lifecycler #2.
1398 cfg = testLifecyclerConfig(ringConfig, "instance-2")
1399 cfg.ReadinessCheckRingHealth = testData.checkRingHealthEnabled
1400 cfg.MinReadyDuration = 0

Callers

nothing calls this directly

Calls 12

CheckReadyMethod · 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
waitRingInstanceFunction · 0.85
RunMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected