(t *testing.T)
| 1341 | } |
| 1342 | |
| 1343 | func 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 |
nothing calls this directly
no test coverage detected