(t *testing.T)
| 376 | } |
| 377 | |
| 378 | func TestBasicLifecycler_HeartbeatWhileStopping(t *testing.T) { |
| 379 | ctx := context.Background() |
| 380 | cfg := prepareBasicLifecyclerConfig() |
| 381 | cfg.HeartbeatPeriod = 10 * time.Millisecond |
| 382 | |
| 383 | lifecycler, delegate, store, err := prepareBasicLifecycler(t, cfg) |
| 384 | require.NoError(t, err) |
| 385 | require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) |
| 386 | |
| 387 | onStoppingCalled := false |
| 388 | |
| 389 | delegate.onStopping = func(_ *BasicLifecycler) { |
| 390 | // Since the hearbeat timestamp is in seconds we would have to wait 1s before we can assert |
| 391 | // on it being changed, regardless the heartbeat period. To speed up this test, we're going |
| 392 | // to reset the timestamp to 0 and then assert it has been updated. |
| 393 | require.NoError(t, store.CAS(ctx, testRingKey, func(in interface{}) (out interface{}, retry bool, err error) { |
| 394 | ringDesc := GetOrCreateRingDesc(in) |
| 395 | instanceDesc := ringDesc.Ingesters[testInstanceID] |
| 396 | instanceDesc.Timestamp = 0 |
| 397 | ringDesc.Ingesters[testInstanceID] = instanceDesc |
| 398 | return ringDesc, true, nil |
| 399 | })) |
| 400 | |
| 401 | // Wait until the timestamp has been updated. |
| 402 | test.Poll(t, time.Second, true, func() interface{} { |
| 403 | desc, _ := getInstanceFromStore(t, store, testInstanceID) |
| 404 | currTimestamp := desc.GetTimestamp() |
| 405 | |
| 406 | return currTimestamp != 0 |
| 407 | }) |
| 408 | |
| 409 | onStoppingCalled = true |
| 410 | } |
| 411 | |
| 412 | assert.NoError(t, services.StopAndAwaitTerminated(ctx, lifecycler)) |
| 413 | assert.True(t, onStoppingCalled) |
| 414 | } |
| 415 | |
| 416 | func TestBasicLifecycler_HeartbeatAfterBackendReset(t *testing.T) { |
| 417 | ctx := context.Background() |
nothing calls this directly
no test coverage detected