Skip to content

Commit

Permalink
[circuit_breaking_drop_reporting] test???
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Jan 22, 2021
1 parent 3e508a3 commit f063116
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions xds/internal/balancer/edsbalancer/eds_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package edsbalancer
import (
"fmt"
"reflect"
"runtime/debug"
"sort"
"testing"
"time"
Expand Down Expand Up @@ -746,6 +747,7 @@ func (s) TestDropPicker(t *testing.T) {
}

func (s) TestEDS_LoadReport(t *testing.T) {
debug.PrintStack()
origCircuitBreakingSupport := env.CircuitBreakingSupport
env.CircuitBreakingSupport = true
defer func() { env.CircuitBreakingSupport = origCircuitBreakingSupport }()
Expand All @@ -762,10 +764,9 @@ func (s) TestEDS_LoadReport(t *testing.T) {
edsb := newEDSBalancerImpl(cc, nil, lsWrapper, nil)
edsb.enqueueChildBalancerStateUpdate = edsb.updateState

const (
testServiceName = "test-service"
cbMaxRequests = 20
)
// var testServiceName = fmt.Sprintf("test-service-%v", time.Now().UnixNano())
var testServiceName = "test-service"
const cbMaxRequests = 20
var maxRequestsTemp uint32 = cbMaxRequests
client.SetMaxRequests(testServiceName, &maxRequestsTemp)
edsb.updateServiceRequestsCounter(testServiceName)
Expand Down Expand Up @@ -808,27 +809,13 @@ func (s) TestEDS_LoadReport(t *testing.T) {
// In the remaining RPCs, only cbMaxRequests are allowed by circuit
// breaking. Others will be dropped by CB.
dropWithCB = rpcCount - dropWithCategory - cbMaxRequests

rpcInProgress = cbMaxRequests / 2 // 50% of RPCs will be never done.
rpcSucceeded = cbMaxRequests / 2 // 50% of RPCs will succeed.
)
wantStoreData := []*load.Data{{
Cluster: testClusterNames[0],
Service: "",
LocalityStats: map[string]load.LocalityData{
locality1JSON: {RequestStats: load.RequestData{InProgress: rpcInProgress}},
locality2JSON: {RequestStats: load.RequestData{Succeeded: rpcSucceeded}},
},
TotalDrops: dropWithCategory + dropWithCB,
Drops: map[string]uint64{
testDropCategory: dropWithCategory,
},
}}

var rpcsToBeDone []balancer.PickResult
// Run the picks, but only pick with sc1 will be done later.
for i := 0; i < rpcCount; i++ {
scst, _ := p1.Pick(balancer.PickInfo{})
scst, err := p1.Pick(balancer.PickInfo{})
fmt.Println(i, scst, err)
if scst.Done != nil && scst.SubConn != sc1 {
rpcsToBeDone = append(rpcsToBeDone, scst)
}
Expand All @@ -837,6 +824,23 @@ func (s) TestEDS_LoadReport(t *testing.T) {
for _, scst := range rpcsToBeDone {
scst.Done(balancer.DoneInfo{})
}
var (
rpcSucceeded = len(rpcsToBeDone)
rpcInProgress = rpcCount - dropWithCategory - dropWithCB - rpcSucceeded
)

wantStoreData := []*load.Data{{
Cluster: testClusterNames[0],
Service: "",
LocalityStats: map[string]load.LocalityData{
locality1JSON: {RequestStats: load.RequestData{InProgress: uint64(rpcInProgress)}},
locality2JSON: {RequestStats: load.RequestData{Succeeded: uint64(rpcSucceeded)}},
},
TotalDrops: dropWithCategory + dropWithCB,
Drops: map[string]uint64{
testDropCategory: dropWithCategory,
},
}}

gotStoreData := loadStore.Stats(testClusterNames[0:1])
if diff := cmp.Diff(wantStoreData, gotStoreData, cmpopts.EquateEmpty(), cmpopts.IgnoreFields(load.Data{}, "ReportInterval")); diff != "" {
Expand Down

0 comments on commit f063116

Please sign in to comment.