@@ -330,25 +330,6 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
330
330
require .NoError (t , err )
331
331
require .NoError (t , services .StartAndAwaitRunning (context .Background (), r ))
332
332
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
-
352
333
// poll function waits for a condition and returning actual state of the ingesters after the condition succeed.
353
334
poll := func (condition func (* Desc ) bool ) map [string ]InstanceDesc {
354
335
var ingesters map [string ]InstanceDesc
@@ -367,17 +348,30 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
367
348
return ingesters
368
349
}
369
350
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 )
373
358
require .NoError (t , err )
374
- require .NoError (t , services .StartAndAwaitRunning (context .Background (), ingester ))
359
+ require .NoError (t , services .StartAndAwaitRunning (context .Background (), lifecycler ))
375
360
poll (func (desc * Desc ) bool {
376
- return len ( desc .Ingesters ) == 2 && desc . Ingesters [ "ing2" ].State == ACTIVE
361
+ return desc .Ingesters [ ingId ].State == ACTIVE
377
362
})
378
- return ingester
363
+ return lifecycler
379
364
}
380
365
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
+
381
375
ingesters := poll (func (desc * Desc ) bool {
382
376
return len (desc .Ingesters ) == 2 && desc .Ingesters ["ing1" ].State == ACTIVE && desc .Ingesters ["ing2" ].State == ACTIVE
383
377
})
@@ -395,7 +389,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
395
389
assert .Equal (t , LEAVING , ingesters ["ing2" ].State )
396
390
397
391
// Start Ingester2 again - Should flip back to ACTIVE in the ring
398
- l2 = startIngester2AndWaitActive ( lifecyclerConfig )
392
+ l2 = startIngesterAndWaitActive ( "ing2" )
399
393
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
400
394
401
395
// 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
409
403
})
410
404
require .NoError (t , err )
411
405
412
- l2 = startIngester2AndWaitActive ( lifecyclerConfig )
406
+ l2 = startIngesterAndWaitActive ( "ing2" )
413
407
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
414
408
415
409
// 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
423
417
})
424
418
require .NoError (t , err )
425
419
426
- l2 = startIngester2AndWaitActive ( lifecyclerConfig )
420
+ l2 = startIngesterAndWaitActive ( "ing2" )
427
421
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
428
422
}
429
423
0 commit comments