@@ -142,7 +142,7 @@ func (s) TestEDS_OneLocality(t *testing.T) {
142
142
}
143
143
144
144
// The same locality, different drop rate, dropping 50%.
145
- clab5 := testutils .NewClusterLoadAssignmentBuilder (testClusterNames [0 ], [ ]uint32 {50 })
145
+ clab5 := testutils .NewClusterLoadAssignmentBuilder (testClusterNames [0 ], map [ string ]uint32 {"test-drop" : 50 })
146
146
clab5 .AddLocality (testSubZones [0 ], 1 , 0 , testEndpointAddrs [2 :3 ], nil )
147
147
edsb .handleEDSResponse (parseEDSRespProtoForTesting (clab5 .Build ()))
148
148
@@ -746,6 +746,10 @@ func (s) TestDropPicker(t *testing.T) {
746
746
}
747
747
748
748
func (s ) TestEDS_LoadReport (t * testing.T ) {
749
+ origCircuitBreakingSupport := env .CircuitBreakingSupport
750
+ env .CircuitBreakingSupport = true
751
+ defer func () { env .CircuitBreakingSupport = origCircuitBreakingSupport }()
752
+
749
753
// We create an xdsClientWrapper with a dummy xdsClientInterface which only
750
754
// implements the LoadStore() method to return the underlying load.Store to
751
755
// be used.
@@ -758,10 +762,20 @@ func (s) TestEDS_LoadReport(t *testing.T) {
758
762
edsb := newEDSBalancerImpl (cc , nil , lsWrapper , nil )
759
763
edsb .enqueueChildBalancerStateUpdate = edsb .updateState
760
764
765
+ const (
766
+ testServiceName = "test-service"
767
+ cbMaxRequests = 20
768
+ )
769
+ var maxRequestsTemp uint32 = cbMaxRequests
770
+ client .SetMaxRequests (testServiceName , & maxRequestsTemp )
771
+ defer client .ClearCounterForTesting (testServiceName )
772
+ edsb .updateServiceRequestsCounter (testServiceName )
773
+
761
774
backendToBalancerID := make (map [balancer.SubConn ]internal.LocalityID )
762
775
776
+ const testDropCategory = "test-drop"
763
777
// Two localities, each with one backend.
764
- clab1 := testutils .NewClusterLoadAssignmentBuilder (testClusterNames [0 ], nil )
778
+ clab1 := testutils .NewClusterLoadAssignmentBuilder (testClusterNames [0 ], map [ string ] uint32 { testDropCategory : 50 } )
765
779
clab1 .AddLocality (testSubZones [0 ], 1 , 0 , testEndpointAddrs [:1 ], nil )
766
780
edsb .handleEDSResponse (parseEDSRespProtoForTesting (clab1 .Build ()))
767
781
sc1 := <- cc .NewSubConnCh
@@ -788,20 +802,42 @@ func (s) TestEDS_LoadReport(t *testing.T) {
788
802
// the picks on sc1 should show up as inProgress.
789
803
locality1JSON , _ := locality1 .ToString ()
790
804
locality2JSON , _ := locality2 .ToString ()
805
+ const (
806
+ rpcCount = 100
807
+ // 50% will be dropped with category testDropCategory.
808
+ dropWithCategory = rpcCount / 2
809
+ // In the remaining RPCs, only cbMaxRequests are allowed by circuit
810
+ // breaking. Others will be dropped by CB.
811
+ dropWithCB = rpcCount - dropWithCategory - cbMaxRequests
812
+
813
+ rpcInProgress = cbMaxRequests / 2 // 50% of RPCs will be never done.
814
+ rpcSucceeded = cbMaxRequests / 2 // 50% of RPCs will succeed.
815
+ )
791
816
wantStoreData := []* load.Data {{
792
817
Cluster : testClusterNames [0 ],
793
818
Service : "" ,
794
819
LocalityStats : map [string ]load.LocalityData {
795
- locality1JSON : {RequestStats : load.RequestData {InProgress : 5 }},
796
- locality2JSON : {RequestStats : load.RequestData {Succeeded : 5 }},
820
+ locality1JSON : {RequestStats : load.RequestData {InProgress : rpcInProgress }},
821
+ locality2JSON : {RequestStats : load.RequestData {Succeeded : rpcSucceeded }},
822
+ },
823
+ TotalDrops : dropWithCategory + dropWithCB ,
824
+ Drops : map [string ]uint64 {
825
+ testDropCategory : dropWithCategory ,
797
826
},
798
827
}}
799
- for i := 0 ; i < 10 ; i ++ {
828
+
829
+ var rpcsToBeDone []balancer.PickResult
830
+ // Run the picks, but only pick with sc1 will be done later.
831
+ for i := 0 ; i < rpcCount ; i ++ {
800
832
scst , _ := p1 .Pick (balancer.PickInfo {})
801
833
if scst .Done != nil && scst .SubConn != sc1 {
802
- scst . Done (balancer. DoneInfo {} )
834
+ rpcsToBeDone = append ( rpcsToBeDone , scst )
803
835
}
804
836
}
837
+ // Call done on those sc1 picks.
838
+ for _ , scst := range rpcsToBeDone {
839
+ scst .Done (balancer.DoneInfo {})
840
+ }
805
841
806
842
gotStoreData := loadStore .Stats (testClusterNames [0 :1 ])
807
843
if diff := cmp .Diff (wantStoreData , gotStoreData , cmpopts .EquateEmpty (), cmpopts .IgnoreFields (load.Data {}, "ReportInterval" )); diff != "" {
0 commit comments