Skip to content

Commit

Permalink
[xds_lrs_disabled] simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Dec 7, 2020
1 parent 0823971 commit 48bc9f3
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions xds/internal/balancer/edsbalancer/eds_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,6 @@ func (s) TestEDS_LoadReportDisabled(t *testing.T) {
// We create an xdsClientWrapper with a dummy xdsClientInterface which only
// implements the LoadStore() method to return the underlying load.Store to
// be used.
loadStore := load.NewStore()
lsWrapper := &loadStoreWrapper{}
lsWrapper.updateServiceName(testClusterNames[0])
// Not calling lsWrapper.updateLoadStore(loadStore) because LRS is disabled.
Expand All @@ -759,44 +758,18 @@ func (s) TestEDS_LoadReportDisabled(t *testing.T) {
edsb := newEDSBalancerImpl(cc, nil, lsWrapper, nil)
edsb.enqueueChildBalancerStateUpdate = edsb.updateState

backendToBalancerID := make(map[balancer.SubConn]internal.LocalityID)

// Two localities, each with one backend.
clab1 := testutils.NewClusterLoadAssignmentBuilder(testClusterNames[0], nil)
clab1.AddLocality(testSubZones[0], 1, 0, testEndpointAddrs[:1], nil)
edsb.handleEDSResponse(parseEDSRespProtoForTesting(clab1.Build()))
sc1 := <-cc.NewSubConnCh
edsb.handleSubConnStateChange(sc1, connectivity.Connecting)
edsb.handleSubConnStateChange(sc1, connectivity.Ready)
locality1 := internal.LocalityID{SubZone: testSubZones[0]}
backendToBalancerID[sc1] = locality1

// Add the second locality later to make sure sc2 belongs to the second
// locality. Otherwise the test is flaky because of a map is used in EDS to
// keep localities.
clab1.AddLocality(testSubZones[1], 1, 0, testEndpointAddrs[1:2], nil)
edsb.handleEDSResponse(parseEDSRespProtoForTesting(clab1.Build()))
sc2 := <-cc.NewSubConnCh
edsb.handleSubConnStateChange(sc2, connectivity.Connecting)
edsb.handleSubConnStateChange(sc2, connectivity.Ready)
locality2 := internal.LocalityID{SubZone: testSubZones[1]}
backendToBalancerID[sc2] = locality2

// Test roundrobin with two subconns.
p1 := <-cc.NewPickerCh
// We expect the 10 picks to be split between the localities since they are
// of equal weight. And since we only mark the picks routed to sc2 as done,
// the picks on sc1 should show up as inProgress.
// We call picks to make sure they don't panic.
for i := 0; i < 10; i++ {
scst, _ := p1.Pick(balancer.PickInfo{})
if scst.Done != nil && scst.SubConn != sc1 {
scst.Done(balancer.DoneInfo{})
}
}

var wantStoreData []*load.Data
gotStoreData := loadStore.Stats(testClusterNames[0:1])
if diff := cmp.Diff(wantStoreData, gotStoreData, cmpopts.EquateEmpty(), cmpopts.IgnoreFields(load.Data{}, "ReportInterval")); diff != "" {
t.Errorf("store.stats() returned unexpected diff (-want +got):\n%s", diff)
p1.Pick(balancer.PickInfo{})
}
}

0 comments on commit 48bc9f3

Please sign in to comment.