Skip to content

Commit

Permalink
add test; fix compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Aug 17, 2021
1 parent e028d9b commit 1e840e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion balancer_conn_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (ccb *ccBalancerWrapper) close() {
}

func (ccb *ccBalancerWrapper) exitIdle() {
cc.balancerWrapper.updateCh.Put(exitIdle{})
ccb.updateCh.Put(exitIdle{})
}

func (ccb *ccBalancerWrapper) handleSubConnStateChange(sc balancer.SubConn, s connectivity.State, err error) {
Expand Down
35 changes: 33 additions & 2 deletions xds/internal/balancer/cdsbalancer/cdsbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ type testEDSBalancer struct {
// resolverErrCh is a channel used to signal a resolver error.
resolverErrCh *testutils.Channel
// closeCh is a channel used to signal the closing of this balancer.
closeCh *testutils.Channel
closeCh *testutils.Channel
exitIdleCh *testutils.Channel
// parentCC is the balancer.ClientConn passed to this test balancer as part
// of the Build() call.
parentCC balancer.ClientConn
Expand All @@ -101,6 +102,7 @@ func newTestEDSBalancer() *testEDSBalancer {
scStateCh: testutils.NewChannel(),
resolverErrCh: testutils.NewChannel(),
closeCh: testutils.NewChannel(),
exitIdleCh: testutils.NewChannel(),
}
}

Expand All @@ -122,7 +124,7 @@ func (tb *testEDSBalancer) Close() {
}

func (tb *testEDSBalancer) ExitIdle() {
// TODO: test
tb.exitIdleCh.Send(struct{}{})
}

// waitForClientConnUpdate verifies if the testEDSBalancer receives the
Expand Down Expand Up @@ -696,6 +698,35 @@ func (s) TestClose(t *testing.T) {
}
}

func (s) TestExitIdle(t *testing.T) {
// This creates a CDS balancer, pushes a ClientConnState update with a fake
// xdsClient, and makes sure that the CDS balancer registers a watch on the
// provided xdsClient.
xdsC, cdsB, edsB, _, cancel := setupWithWatch(t)
defer func() {
cancel()
cdsB.Close()
}()

// Here we invoke the watch callback registered on the fake xdsClient. This
// will trigger the watch handler on the CDS balancer, which will attempt to
// create a new EDS balancer. The fake EDS balancer created above will be
// returned to the CDS balancer, because we have overridden the
// newChildBalancer function as part of test setup.
cdsUpdate := xdsclient.ClusterUpdate{ClusterName: serviceName}
wantCCS := edsCCS(serviceName, nil, false)
ctx, ctxCancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer ctxCancel()
if err := invokeWatchCbAndWait(ctx, xdsC, cdsWatchInfo{cdsUpdate, nil}, wantCCS, edsB); err != nil {
t.Fatal(err)
}

// Call ExitIdle on the CDS balancer.
cdsB.ExitIdle()

edsB.exitIdleCh.Receive(ctx)
}

// TestParseConfig verifies the ParseConfig() method in the CDS balancer.
func (s) TestParseConfig(t *testing.T) {
bb := balancer.Get(cdsName)
Expand Down

0 comments on commit 1e840e8

Please sign in to comment.