@@ -330,6 +330,10 @@ 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
333
337
lifecyclerConfig := testLifecyclerConfig (ringConfig , "ing1" )
334
338
lifecyclerConfig .UnregisterOnShutdown = false
335
339
lifecyclerConfig .HeartbeatPeriod = 0
@@ -345,7 +349,8 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
345
349
require .NoError (t , err )
346
350
require .NoError (t , services .StartAndAwaitRunning (context .Background (), l2 ))
347
351
348
- pool := func (condition func (* Desc ) bool ) map [string ]InstanceDesc {
352
+ // poll function waits for a condition and returning actual state of the ingesters after the condition succeed.
353
+ poll := func (condition func (* Desc ) bool ) map [string ]InstanceDesc {
349
354
var ingesters map [string ]InstanceDesc
350
355
test .Poll (t , 5 * time .Second , true , func () interface {} {
351
356
d , err := r .KVClient .Get (context .Background (), IngesterRingKey )
@@ -362,22 +367,18 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
362
367
return ingesters
363
368
}
364
369
365
- startIngesterAndWaitActive := func (lcConfig LifecyclerConfig ) * Lifecycler {
370
+ // Starts Ingester2 and wait it to became active
371
+ startIngester2AndWaitActive := func (lcConfig LifecyclerConfig ) * Lifecycler {
366
372
ingester , err := NewLifecycler (lcConfig , & noopFlushTransferer {}, "ingester" , IngesterRingKey , true , nil )
367
373
require .NoError (t , err )
368
374
require .NoError (t , services .StartAndAwaitRunning (context .Background (), ingester ))
369
-
370
- ingesters := pool (func (desc * Desc ) bool {
371
- return len (desc .Ingesters ) == 2 && desc .Ingesters ["ing1" ].State == ACTIVE && desc .Ingesters ["ing2" ].State == ACTIVE
375
+ poll (func (desc * Desc ) bool {
376
+ return len (desc .Ingesters ) == 2 && desc .Ingesters ["ing2" ].State == ACTIVE
372
377
})
373
-
374
- assert .Equal (t , ACTIVE , ingesters ["ing1" ].State )
375
- assert .Equal (t , ACTIVE , ingesters ["ing2" ].State )
376
-
377
378
return ingester
378
379
}
379
380
380
- ingesters := pool (func (desc * Desc ) bool {
381
+ ingesters := poll (func (desc * Desc ) bool {
381
382
return len (desc .Ingesters ) == 2 && desc .Ingesters ["ing1" ].State == ACTIVE && desc .Ingesters ["ing2" ].State == ACTIVE
382
383
})
383
384
@@ -388,16 +389,16 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
388
389
// Stop One ingester gracefully should leave it on LEAVING STATE on the ring
389
390
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
390
391
391
- ingesters = pool (func (desc * Desc ) bool {
392
+ ingesters = poll (func (desc * Desc ) bool {
392
393
return len (desc .Ingesters ) == 2 && desc .Ingesters ["ing2" ].State == LEAVING
393
394
})
394
395
assert .Equal (t , LEAVING , ingesters ["ing2" ].State )
395
396
396
397
// Start Ingester2 again - Should flip back to ACTIVE in the ring
397
- l2 = startIngesterAndWaitActive (lifecyclerConfig )
398
+ l2 = startIngester2AndWaitActive (lifecyclerConfig )
398
399
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
399
400
400
- //Simulate ingester2 crash on startup and left the ring with JOINING state
401
+ // Simulate ingester2 crash on startup and left the ring with JOINING state
401
402
err = r .KVClient .CAS (context .Background (), IngesterRingKey , func (in interface {}) (out interface {}, retry bool , err error ) {
402
403
desc , ok := in .(* Desc )
403
404
require .Equal (t , true , ok )
@@ -408,10 +409,10 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
408
409
})
409
410
require .NoError (t , err )
410
411
411
- l2 = startIngesterAndWaitActive (lifecyclerConfig )
412
+ l2 = startIngester2AndWaitActive (lifecyclerConfig )
412
413
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
413
414
414
- //Simulate ingester2 crash on startup and left the ring with PENDING state
415
+ // Simulate ingester2 crash on startup and left the ring with PENDING state
415
416
err = r .KVClient .CAS (context .Background (), IngesterRingKey , func (in interface {}) (out interface {}, retry bool , err error ) {
416
417
desc , ok := in .(* Desc )
417
418
require .Equal (t , true , ok )
@@ -422,7 +423,7 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi
422
423
})
423
424
require .NoError (t , err )
424
425
425
- l2 = startIngesterAndWaitActive (lifecyclerConfig )
426
+ l2 = startIngester2AndWaitActive (lifecyclerConfig )
426
427
require .NoError (t , services .StopAndAwaitTerminated (context .Background (), l2 ))
427
428
}
428
429
0 commit comments