@@ -494,6 +494,7 @@ func TestDistributor_PushIngestionRateLimiter(t *testing.T) {
494494}
495495
496496func TestPush_QuorumError (t * testing.T ) {
497+
497498 var limits validation.Limits
498499 flagext .DefaultValues (& limits )
499500
@@ -513,13 +514,16 @@ func TestPush_QuorumError(t *testing.T) {
513514
514515 d := dists [0 ]
515516
517+ // we should run several write request to make sure we dont have any race condition on the batchTracker#record code
518+ numberOfWrites := 10000
519+
516520 // Using 429 just to make sure we are not hitting the &limits
517521 // Simulating 2 4xx and 1 5xx -> Should return 4xx
518522 ingesters [0 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
519523 ingesters [1 ].failResp .Store (httpgrpc .Errorf (500 , "InternalServerError" ))
520524 ingesters [2 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
521525
522- for i := 0 ; i < 1000 ; i ++ {
526+ for i := 0 ; i < numberOfWrites ; i ++ {
523527 request := makeWriteRequest (0 , 30 , 20 )
524528 _ , err := d .Push (ctx , request )
525529 status , ok := status .FromError (err )
@@ -532,7 +536,7 @@ func TestPush_QuorumError(t *testing.T) {
532536 ingesters [1 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
533537 ingesters [2 ].failResp .Store (httpgrpc .Errorf (500 , "InternalServerError" ))
534538
535- for i := 0 ; i < 10000 ; i ++ {
539+ for i := 0 ; i < numberOfWrites ; i ++ {
536540 request := makeWriteRequest (0 , 300 , 200 )
537541 _ , err := d .Push (ctx , request )
538542 status , ok := status .FromError (err )
@@ -545,7 +549,7 @@ func TestPush_QuorumError(t *testing.T) {
545549 ingesters [1 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
546550 ingesters [2 ].happy .Store (true )
547551
548- for i := 0 ; i < 1 ; i ++ {
552+ for i := 0 ; i < numberOfWrites ; i ++ {
549553 request := makeWriteRequest (0 , 30 , 20 )
550554 _ , err := d .Push (ctx , request )
551555 status , ok := status .FromError (err )
@@ -569,18 +573,6 @@ func TestPush_QuorumError(t *testing.T) {
569573 ingesters [1 ].happy .Store (true )
570574 ingesters [2 ].happy .Store (true )
571575
572- // Wait group to check when the ring got updated
573- wg := & sync.WaitGroup {}
574- wg .Add (1 )
575-
576- go func () {
577- r .KVClient .WatchKey (context .Background (), ingester .RingKey , func (i interface {}) bool {
578- wg .Done ()
579- // False will terminate the watch
580- return false
581- })
582- }()
583-
584576 err := r .KVClient .CAS (context .Background (), ingester .RingKey , func (in interface {}) (interface {}, bool , error ) {
585577 r := in .(* ring.Desc )
586578 ingester2 := r .Ingesters ["2" ]
@@ -593,9 +585,15 @@ func TestPush_QuorumError(t *testing.T) {
593585 require .NoError (t , err )
594586
595587 // Give time to the ring get updated with the KV value
596- wg .Wait ()
588+ for {
589+ replicationSet , _ := r .GetAllHealthy (ring .Read )
590+ if len (replicationSet .Instances ) == 2 {
591+ break
592+ }
593+ time .Sleep (100 * time .Millisecond )
594+ }
597595
598- for i := 0 ; i < 1000 ; i ++ {
596+ for i := 0 ; i < numberOfWrites ; i ++ {
599597 request := makeWriteRequest (0 , 30 , 20 )
600598 _ , err := d .Push (ctx , request )
601599 require .Error (t , err )
0 commit comments