@@ -494,6 +494,7 @@ func TestDistributor_PushIngestionRateLimiter(t *testing.T) {
494
494
}
495
495
496
496
func TestPush_QuorumError (t * testing.T ) {
497
+
497
498
var limits validation.Limits
498
499
flagext .DefaultValues (& limits )
499
500
@@ -513,13 +514,16 @@ func TestPush_QuorumError(t *testing.T) {
513
514
514
515
d := dists [0 ]
515
516
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
+
516
520
// Using 429 just to make sure we are not hitting the &limits
517
521
// Simulating 2 4xx and 1 5xx -> Should return 4xx
518
522
ingesters [0 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
519
523
ingesters [1 ].failResp .Store (httpgrpc .Errorf (500 , "InternalServerError" ))
520
524
ingesters [2 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
521
525
522
- for i := 0 ; i < 1000 ; i ++ {
526
+ for i := 0 ; i < numberOfWrites ; i ++ {
523
527
request := makeWriteRequest (0 , 30 , 20 )
524
528
_ , err := d .Push (ctx , request )
525
529
status , ok := status .FromError (err )
@@ -532,7 +536,7 @@ func TestPush_QuorumError(t *testing.T) {
532
536
ingesters [1 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
533
537
ingesters [2 ].failResp .Store (httpgrpc .Errorf (500 , "InternalServerError" ))
534
538
535
- for i := 0 ; i < 10000 ; i ++ {
539
+ for i := 0 ; i < numberOfWrites ; i ++ {
536
540
request := makeWriteRequest (0 , 300 , 200 )
537
541
_ , err := d .Push (ctx , request )
538
542
status , ok := status .FromError (err )
@@ -545,7 +549,7 @@ func TestPush_QuorumError(t *testing.T) {
545
549
ingesters [1 ].failResp .Store (httpgrpc .Errorf (429 , "Throttling" ))
546
550
ingesters [2 ].happy .Store (true )
547
551
548
- for i := 0 ; i < 1 ; i ++ {
552
+ for i := 0 ; i < numberOfWrites ; i ++ {
549
553
request := makeWriteRequest (0 , 30 , 20 )
550
554
_ , err := d .Push (ctx , request )
551
555
status , ok := status .FromError (err )
@@ -569,18 +573,6 @@ func TestPush_QuorumError(t *testing.T) {
569
573
ingesters [1 ].happy .Store (true )
570
574
ingesters [2 ].happy .Store (true )
571
575
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
-
584
576
err := r .KVClient .CAS (context .Background (), ingester .RingKey , func (in interface {}) (interface {}, bool , error ) {
585
577
r := in .(* ring.Desc )
586
578
ingester2 := r .Ingesters ["2" ]
@@ -593,9 +585,15 @@ func TestPush_QuorumError(t *testing.T) {
593
585
require .NoError (t , err )
594
586
595
587
// 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
+ }
597
595
598
- for i := 0 ; i < 1000 ; i ++ {
596
+ for i := 0 ; i < numberOfWrites ; i ++ {
599
597
request := makeWriteRequest (0 , 30 , 20 )
600
598
_ , err := d .Push (ctx , request )
601
599
require .Error (t , err )
0 commit comments