Skip to content

Commit

Permalink
[xds_service_config_new_fields] fix building errors after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Nov 1, 2019
1 parent ac2a82f commit 9071527
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
2 changes: 1 addition & 1 deletion xds/internal/balancer/xds.go
Expand Up @@ -191,7 +191,7 @@ func (x *xdsBalancer) startNewXDSClient(u *XDSConfig) {
prevClient.close()
}
}
x.client = newXDSClient(u.BalancerName, u.ChildPolicy == nil, u.EdsServiceName, x.buildOpts, x.loadStore, newADS, loseContact, exitCleanup)
x.client = newXDSClient(u.BalancerName, u.EdsServiceName, x.buildOpts, x.loadStore, newADS, loseContact, exitCleanup)
go x.client.run()
}

Expand Down
3 changes: 1 addition & 2 deletions xds/internal/balancer/xds_client.go
Expand Up @@ -213,9 +213,8 @@ func (c *client) adsCallAttempt() (firstRespReceived bool) {
}
}

func newXDSClient(balancerName string, enableCDS bool, edsServiceName string, opts balancer.BuildOptions, loadStore lrs.Store, newADS func(context.Context, proto.Message) error, loseContact func(ctx context.Context), exitCleanup func()) *client {
func newXDSClient(balancerName string, edsServiceName string, opts balancer.BuildOptions, loadStore lrs.Store, newADS func(context.Context, proto.Message) error, loseContact func(ctx context.Context), exitCleanup func()) *client {
c := &client{
enableCDS: enableCDS,
serviceName: edsServiceName,
dialer: opts.Dialer,
channelzParentID: opts.ChannelzParentID,
Expand Down
41 changes: 14 additions & 27 deletions xds/internal/balancer/xds_client_test.go
Expand Up @@ -45,16 +45,12 @@ import (
var (
testServiceName = "test/foo"
testEDSServiceName = "test/service/eds"
testCDSReq = &discoverypb.DiscoveryRequest{
TypeUrl: cdsType,
ResourceNames: []string{testServiceName},
}
testEDSReq = &discoverypb.DiscoveryRequest{
testEDSReq = &xdspb.DiscoveryRequest{
TypeUrl: edsType,
// TODO: this should be cluster name from CDS response, not the service name.
ResourceNames: []string{testServiceName},
}
testEDSReqWithoutEndpoints = &discoverypb.DiscoveryRequest{
testEDSReqWithoutEndpoints = &xdspb.DiscoveryRequest{
TypeUrl: edsType,
ResourceNames: []string{testServiceName},
}
Expand Down Expand Up @@ -187,10 +183,9 @@ func newTestTrafficDirector() *testTrafficDirector {
}

type testConfig struct {
doCDS bool
edsServiceName string
expectedRequests []*discoverypb.DiscoveryRequest
responsesToSend []*discoverypb.DiscoveryResponse
expectedRequests []*xdspb.DiscoveryRequest
responsesToSend []*xdspb.DiscoveryResponse
expectedADSResponses []proto.Message
adsErr error
svrErr error
Expand Down Expand Up @@ -222,26 +217,18 @@ func setupServer(t *testing.T) (addr string, td *testTrafficDirector, lrss *lrsS
func (s) TestXdsClientResponseHandling(t *testing.T) {
for _, test := range []*testConfig{
{
doCDS: true,
expectedRequests: []*discoverypb.DiscoveryRequest{testCDSReq, testEDSReq},
responsesToSend: []*discoverypb.DiscoveryResponse{testCDSResp, testEDSResp},
expectedADSResponses: []proto.Message{testCluster, testClusterLoadAssignment},
},
{
doCDS: false,
expectedRequests: []*discoverypb.DiscoveryRequest{testEDSReqWithoutEndpoints},
responsesToSend: []*discoverypb.DiscoveryResponse{testEDSRespWithoutEndpoints},
expectedADSResponses: []proto.Message{testClusterLoadAssignmentWithoutEndpoints},
expectedRequests: []*xdspb.DiscoveryRequest{testEDSReq},
responsesToSend: []*xdspb.DiscoveryResponse{testEDSResp},
expectedADSResponses: []proto.Message{testClusterLoadAssignment},
},
{
doCDS: false,
edsServiceName: testEDSServiceName,
expectedRequests: []*discoverypb.DiscoveryRequest{{
expectedRequests: []*xdspb.DiscoveryRequest{{
TypeUrl: edsType,
ResourceNames: []string{testEDSServiceName},
}},
responsesToSend: []*discoverypb.DiscoveryResponse{testEDSRespWithoutEndpoints},
expectedADSResponses: []proto.Message{testClusterLoadAssignmentWithoutEndpoints},
responsesToSend: []*xdspb.DiscoveryResponse{testEDSResp},
expectedADSResponses: []proto.Message{testClusterLoadAssignment},
},
} {
testXdsClientResponseHandling(t, test)
Expand All @@ -256,7 +243,7 @@ func testXdsClientResponseHandling(t *testing.T, test *testConfig) {
adsChan <- i
return nil
}
client := newXDSClient(addr, test.doCDS, test.edsServiceName, balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, func(context.Context) {}, func() {})
client := newXDSClient(addr, test.edsServiceName, balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, func(context.Context) {}, func() {})
defer client.close()
go client.run()

Expand Down Expand Up @@ -313,7 +300,7 @@ func testXdsClientLoseContactRemoteClose(t *testing.T, test *testConfig) {
loseContactFunc := func(context.Context) {
contactChan <- &loseContact{}
}
client := newXDSClient(addr, test.doCDS, test.edsServiceName, balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, loseContactFunc, func() {})
client := newXDSClient(addr, test.edsServiceName, balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, loseContactFunc, func() {})
defer client.close()
go client.run()

Expand Down Expand Up @@ -347,7 +334,7 @@ func testXdsClientLoseContactADSRelatedErrorOccur(t *testing.T, test *testConfig
loseContactFunc := func(context.Context) {
contactChan <- &loseContact{}
}
client := newXDSClient(addr, test.doCDS, test.edsServiceName, balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, loseContactFunc, func() {})
client := newXDSClient(addr, test.edsServiceName, balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, loseContactFunc, func() {})
defer client.close()
go client.run()

Expand Down Expand Up @@ -381,7 +368,7 @@ func (s) TestXdsClientExponentialRetry(t *testing.T) {
loseContactFunc := func(context.Context) {
contactChan <- &loseContact{}
}
client := newXDSClient(addr, cfg.doCDS, "", balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, loseContactFunc, func() {})
client := newXDSClient(addr, "", balancer.BuildOptions{Target: resolver.Target{Endpoint: testServiceName}}, nil, newADS, loseContactFunc, func() {})
defer client.close()
go client.run()

Expand Down
15 changes: 4 additions & 11 deletions xds/internal/balancer/xds_test.go
Expand Up @@ -178,7 +178,7 @@ type scStateChange struct {

type fakeEDSBalancer struct {
cc balancer.ClientConn
edsChan chan *edspb.ClusterLoadAssignment
edsChan chan *xdspb.ClusterLoadAssignment
childPolicy chan *loadBalancingConfig
fallbackPolicy chan *loadBalancingConfig
subconnStateChange chan *scStateChange
Expand Down Expand Up @@ -209,7 +209,7 @@ func (f *fakeEDSBalancer) HandleChildPolicy(name string, config json.RawMessage)
func newFakeEDSBalancer(cc balancer.ClientConn, loadStore lrs.Store) edsBalancerInterface {
lb := &fakeEDSBalancer{
cc: cc,
edsChan: make(chan *edspb.ClusterLoadAssignment, 10),
edsChan: make(chan *xdspb.ClusterLoadAssignment, 10),
childPolicy: make(chan *loadBalancingConfig, 10),
fallbackPolicy: make(chan *loadBalancingConfig, 10),
subconnStateChange: make(chan *scStateChange, 10),
Expand Down Expand Up @@ -389,7 +389,7 @@ func (s) TestXdsBalanceHandleBalancerConfigChildPolicyUpdate(t *testing.T) {
}()
for _, test := range []struct {
cfg *XDSConfig
responseToSend *discoverypb.DiscoveryResponse
responseToSend *xdspb.DiscoveryResponse
expectedChildPolicy *loadBalancingConfig
}{
{
Expand All @@ -399,7 +399,7 @@ func (s) TestXdsBalanceHandleBalancerConfigChildPolicyUpdate(t *testing.T) {
Config: json.RawMessage("{}"),
},
},
responseToSend: testEDSRespWithoutEndpoints,
responseToSend: testEDSResp,
expectedChildPolicy: &loadBalancingConfig{
Name: string(fakeBalancerA),
Config: json.RawMessage(`{}`),
Expand All @@ -417,13 +417,6 @@ func (s) TestXdsBalanceHandleBalancerConfigChildPolicyUpdate(t *testing.T) {
Config: json.RawMessage(`{}`),
},
},
{
cfg: &XDSConfig{},
responseToSend: testCDSResp,
expectedChildPolicy: &loadBalancingConfig{
Name: "ROUND_ROBIN",
},
},
} {
addr, td, _, cleanup := setupServer(t)
cleanups = append(cleanups, cleanup)
Expand Down

0 comments on commit 9071527

Please sign in to comment.