@@ -28,7 +28,6 @@ import (
2828
2929 "github.com/google/go-cmp/cmp"
3030 "github.com/google/go-cmp/cmp/cmpopts"
31- "google.golang.org/grpc/attributes"
3231 "google.golang.org/grpc/balancer"
3332 "google.golang.org/grpc/connectivity"
3433 "google.golang.org/grpc/internal"
@@ -129,7 +128,10 @@ func (tb *testEDSBalancer) waitForClientConnUpdate(ctx context.Context, wantCCS
129128 return err
130129 }
131130 gotCCS := ccs .(balancer.ClientConnState )
132- if ! cmp .Equal (gotCCS , wantCCS , cmpopts .IgnoreUnexported (attributes.Attributes {})) {
131+ if xdsclient .FromResolverState (gotCCS .ResolverState ) == nil {
132+ return fmt .Errorf ("want resolver state with XDSClient attached, got one without" )
133+ }
134+ if ! cmp .Equal (gotCCS , wantCCS , cmpopts .IgnoreFields (resolver.State {}, "Attributes" )) {
133135 return fmt .Errorf ("received ClientConnState: %+v, want %+v" , gotCCS , wantCCS )
134136 }
135137 return nil
@@ -173,7 +175,7 @@ func (tb *testEDSBalancer) waitForClose(ctx context.Context) error {
173175
174176// cdsCCS is a helper function to construct a good update passed from the
175177// xdsResolver to the cdsBalancer.
176- func cdsCCS (cluster string ) balancer.ClientConnState {
178+ func cdsCCS (cluster string , xdsC xdsclient. XDSClient ) balancer.ClientConnState {
177179 const cdsLBConfig = `{
178180 "loadBalancingConfig":[
179181 {
@@ -185,9 +187,9 @@ func cdsCCS(cluster string) balancer.ClientConnState {
185187 }`
186188 jsonSC := fmt .Sprintf (cdsLBConfig , cluster )
187189 return balancer.ClientConnState {
188- ResolverState : resolver.State {
190+ ResolverState : xdsclient . SetClient ( resolver.State {
189191 ServiceConfig : internal .ParseServiceConfigForTesting .(func (string ) * serviceconfig.ParseResult )(jsonSC ),
190- },
192+ }, xdsC ),
191193 BalancerConfig : & lbConfig {ClusterName : clusterName },
192194 }
193195}
@@ -211,11 +213,7 @@ func edsCCS(service string, countMax *uint32, enableLRS bool) balancer.ClientCon
211213// newEDSBalancer function to return it), and also returns a cleanup function.
212214func setup (t * testing.T ) (* fakeclient.Client , * cdsBalancer , * testEDSBalancer , * xdstestutils.TestClientConn , func ()) {
213215 t .Helper ()
214-
215216 xdsC := fakeclient .NewClient ()
216- oldNewXDSClient := newXDSClient
217- newXDSClient = func () (xdsClient , error ) { return xdsC , nil }
218-
219217 builder := balancer .Get (cdsName )
220218 if builder == nil {
221219 t .Fatalf ("balancer.Get(%q) returned nil" , cdsName )
@@ -232,7 +230,7 @@ func setup(t *testing.T) (*fakeclient.Client, *cdsBalancer, *testEDSBalancer, *x
232230
233231 return xdsC , cdsB .(* cdsBalancer ), edsB , tcc , func () {
234232 newEDSBalancer = oldEDSBalancerBuilder
235- newXDSClient = oldNewXDSClient
233+ xdsC . Close ()
236234 }
237235}
238236
@@ -242,7 +240,7 @@ func setupWithWatch(t *testing.T) (*fakeclient.Client, *cdsBalancer, *testEDSBal
242240 t .Helper ()
243241
244242 xdsC , cdsB , edsB , tcc , cancel := setup (t )
245- if err := cdsB .UpdateClientConnState (cdsCCS (clusterName )); err != nil {
243+ if err := cdsB .UpdateClientConnState (cdsCCS (clusterName , xdsC )); err != nil {
246244 t .Fatalf ("cdsBalancer.UpdateClientConnState failed with error: %v" , err )
247245 }
248246
@@ -262,6 +260,9 @@ func setupWithWatch(t *testing.T) (*fakeclient.Client, *cdsBalancer, *testEDSBal
262260// cdsBalancer with different inputs and verifies that the CDS watch API on the
263261// provided xdsClient is invoked appropriately.
264262func (s ) TestUpdateClientConnState (t * testing.T ) {
263+ xdsC := fakeclient .NewClient ()
264+ defer xdsC .Close ()
265+
265266 tests := []struct {
266267 name string
267268 ccs balancer.ClientConnState
@@ -280,14 +281,14 @@ func (s) TestUpdateClientConnState(t *testing.T) {
280281 },
281282 {
282283 name : "happy-good-case" ,
283- ccs : cdsCCS (clusterName ),
284+ ccs : cdsCCS (clusterName , xdsC ),
284285 wantCluster : clusterName ,
285286 },
286287 }
287288
288289 for _ , test := range tests {
289290 t .Run (test .name , func (t * testing.T ) {
290- xdsC , cdsB , _ , _ , cancel := setup (t )
291+ _ , cdsB , _ , _ , cancel := setup (t )
291292 defer func () {
292293 cancel ()
293294 cdsB .Close ()
@@ -324,7 +325,7 @@ func (s) TestUpdateClientConnStateWithSameState(t *testing.T) {
324325 }()
325326
326327 // This is the same clientConn update sent in setupWithWatch().
327- if err := cdsB .UpdateClientConnState (cdsCCS (clusterName )); err != nil {
328+ if err := cdsB .UpdateClientConnState (cdsCCS (clusterName , xdsC )); err != nil {
328329 t .Fatalf ("cdsBalancer.UpdateClientConnState failed with error: %v" , err )
329330 }
330331 // The above update should not result in a new watch being registered.
@@ -660,7 +661,7 @@ func (s) TestClose(t *testing.T) {
660661
661662 // Make sure that the UpdateClientConnState() method on the CDS balancer
662663 // returns error.
663- if err := cdsB .UpdateClientConnState (cdsCCS (clusterName )); err != errBalancerClosed {
664+ if err := cdsB .UpdateClientConnState (cdsCCS (clusterName , xdsC )); err != errBalancerClosed {
664665 t .Fatalf ("UpdateClientConnState() after close returned %v, want %v" , err , errBalancerClosed )
665666 }
666667
0 commit comments