Skip to content

Commit f8b484d

Browse files
committed
Addressing comments on test
Signed-off-by: Alan Protasio <[email protected]>
1 parent 6092356 commit f8b484d

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

pkg/ring/lifecycler_test.go

+22-28
Original file line numberDiff line numberDiff line change
@@ -330,25 +330,6 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
330330
require.NoError(t, err)
331331
require.NoError(t, services.StartAndAwaitRunning(context.Background(), r))
332332

333-
// We are going to create 2 fake ingester with disabled heart beat and `unregister_on_shutdown=false` then
334-
// test if the ingester 2 became active after:
335-
// * Clean Shutdown (LEAVING after shutdown)
336-
// * Crashes while in the PENDING or JOINING state
337-
lifecyclerConfig := testLifecyclerConfig(ringConfig, "ing1")
338-
lifecyclerConfig.UnregisterOnShutdown = false
339-
lifecyclerConfig.HeartbeatPeriod = 0
340-
341-
l1, err := NewLifecycler(lifecyclerConfig, &noopFlushTransferer{}, "ingester", IngesterRingKey, true, nil)
342-
require.NoError(t, err)
343-
require.NoError(t, services.StartAndAwaitRunning(context.Background(), l1))
344-
defer services.StopAndAwaitTerminated(context.Background(), l1) //nolint:errcheck
345-
346-
lifecyclerConfig.ID = "ing2"
347-
348-
l2, err := NewLifecycler(lifecyclerConfig, &noopFlushTransferer{}, "ingester", IngesterRingKey, true, nil)
349-
require.NoError(t, err)
350-
require.NoError(t, services.StartAndAwaitRunning(context.Background(), l2))
351-
352333
// poll function waits for a condition and returning actual state of the ingesters after the condition succeed.
353334
poll := func(condition func(*Desc) bool) map[string]InstanceDesc {
354335
var ingesters map[string]InstanceDesc
@@ -367,17 +348,30 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
367348
return ingesters
368349
}
369350

370-
// Starts Ingester2 and wait it to became active
371-
startIngester2AndWaitActive := func(lcConfig LifecyclerConfig) *Lifecycler {
372-
ingester, err := NewLifecycler(lcConfig, &noopFlushTransferer{}, "ingester", IngesterRingKey, true, nil)
351+
// Starts Ingester and wait it to became active
352+
startIngesterAndWaitActive := func(ingId string) *Lifecycler {
353+
lifecyclerConfig := testLifecyclerConfig(ringConfig, ingId)
354+
// Disabling heartBeat and unregister_on_shutdown
355+
lifecyclerConfig.UnregisterOnShutdown = false
356+
lifecyclerConfig.HeartbeatPeriod = 0
357+
lifecycler, err := NewLifecycler(lifecyclerConfig, &noopFlushTransferer{}, "lifecycler", IngesterRingKey, true, nil)
373358
require.NoError(t, err)
374-
require.NoError(t, services.StartAndAwaitRunning(context.Background(), ingester))
359+
require.NoError(t, services.StartAndAwaitRunning(context.Background(), lifecycler))
375360
poll(func(desc *Desc) bool {
376-
return len(desc.Ingesters) == 2 && desc.Ingesters["ing2"].State == ACTIVE
361+
return desc.Ingesters[ingId].State == ACTIVE
377362
})
378-
return ingester
363+
return lifecycler
379364
}
380365

366+
// We are going to create 2 fake ingester with disabled heart beat and `unregister_on_shutdown=false` then
367+
// test if the ingester 2 became active after:
368+
// * Clean Shutdown (LEAVING after shutdown)
369+
// * Crashes while in the PENDING or JOINING state
370+
l1 := startIngesterAndWaitActive("ing1")
371+
defer services.StopAndAwaitTerminated(context.Background(), l1) //nolint:errcheck
372+
373+
l2 := startIngesterAndWaitActive("ing2")
374+
381375
ingesters := poll(func(desc *Desc) bool {
382376
return len(desc.Ingesters) == 2 && desc.Ingesters["ing1"].State == ACTIVE && desc.Ingesters["ing2"].State == ACTIVE
383377
})
@@ -395,7 +389,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
395389
assert.Equal(t, LEAVING, ingesters["ing2"].State)
396390

397391
// Start Ingester2 again - Should flip back to ACTIVE in the ring
398-
l2 = startIngester2AndWaitActive(lifecyclerConfig)
392+
l2 = startIngesterAndWaitActive("ing2")
399393
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2))
400394

401395
// Simulate ingester2 crash on startup and left the ring with JOINING state
@@ -409,7 +403,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
409403
})
410404
require.NoError(t, err)
411405

412-
l2 = startIngester2AndWaitActive(lifecyclerConfig)
406+
l2 = startIngesterAndWaitActive("ing2")
413407
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2))
414408

415409
// Simulate ingester2 crash on startup and left the ring with PENDING state
@@ -423,7 +417,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
423417
})
424418
require.NoError(t, err)
425419

426-
l2 = startIngester2AndWaitActive(lifecyclerConfig)
420+
l2 = startIngesterAndWaitActive("ing2")
427421
require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2))
428422
}
429423

0 commit comments

Comments
 (0)