@@ -20,9 +20,7 @@ package clusterimpl
2020
2121import  (
2222	"context" 
23- 	"encoding/json" 
2423	"errors" 
25- 	"strings" 
2624	"testing" 
2725	"time" 
2826
@@ -38,7 +36,6 @@ import (
3836	"google.golang.org/grpc/internal/xds/testutils/fakeclient" 
3937	"google.golang.org/grpc/internal/xds/xdsclient" 
4038	"google.golang.org/grpc/resolver" 
41- 	"google.golang.org/grpc/serviceconfig" 
4239)
4340
4441const  (
@@ -70,9 +67,6 @@ func init() {
7067// are handled in the run() goroutine, which exits before Close() returns, we 
7168// expect the above picker update to be dropped. 
7269func  (s ) TestPickerUpdateAfterClose (t  * testing.T ) {
73- 	defer  xdsclient .ClearCounterForTesting (testClusterName , testServiceName )
74- 	xdsC  :=  fakeclient .NewClient ()
75- 
7670	builder  :=  balancer .Get (Name )
7771	cc  :=  testutils .NewBalancerClientConn (t )
7872	b  :=  builder .Build (cc , balancer.BuildOptions {})
@@ -107,6 +101,7 @@ func (s) TestPickerUpdateAfterClose(t *testing.T) {
107101	})
108102
109103	var  maxRequest  uint32  =  50 
104+ 	xdsC  :=  fakeclient .NewClient ()
110105	if  err  :=  b .UpdateClientConnState (balancer.ClientConnState {
111106		ResolverState : xdsclient .SetClient (resolver.State {Endpoints : testBackendEndpoints }, xdsC ),
112107		BalancerConfig : & LBConfig {
@@ -143,14 +138,12 @@ func (s) TestClusterNameInAddressAttributes(t *testing.T) {
143138	ctx , cancel  :=  context .WithTimeout (context .Background (), defaultTestTimeout )
144139	defer  cancel ()
145140
146- 	defer  xdsclient .ClearCounterForTesting (testClusterName , testServiceName )
147- 	xdsC  :=  fakeclient .NewClient ()
148- 
149141	builder  :=  balancer .Get (Name )
150142	cc  :=  testutils .NewBalancerClientConn (t )
151143	b  :=  builder .Build (cc , balancer.BuildOptions {})
152144	defer  b .Close ()
153145
146+ 	xdsC  :=  fakeclient .NewClient ()
154147	if  err  :=  b .UpdateClientConnState (balancer.ClientConnState {
155148		ResolverState : xdsclient .SetClient (resolver.State {Endpoints : testBackendEndpoints }, xdsC ),
156149		BalancerConfig : & LBConfig {
@@ -212,108 +205,6 @@ func (s) TestClusterNameInAddressAttributes(t *testing.T) {
212205	}
213206}
214207
215- // Test verifies that child policies was updated on receipt of 
216- // configuration update. 
217- func  (s ) TestChildPolicyUpdatedOnConfigUpdate (t  * testing.T ) {
218- 	xdsC  :=  fakeclient .NewClient ()
219- 
220- 	builder  :=  balancer .Get (Name )
221- 	cc  :=  testutils .NewBalancerClientConn (t )
222- 	b  :=  builder .Build (cc , balancer.BuildOptions {})
223- 	defer  b .Close ()
224- 
225- 	// Keep track of which child policy was updated 
226- 	updatedChildPolicy  :=  "" 
227- 
228- 	// Create stub balancers to track config updates 
229- 	const  (
230- 		childPolicyName1  =  "stubBalancer1" 
231- 		childPolicyName2  =  "stubBalancer2" 
232- 	)
233- 
234- 	stub .Register (childPolicyName1 , stub.BalancerFuncs {
235- 		UpdateClientConnState : func (_  * stub.BalancerData , _  balancer.ClientConnState ) error  {
236- 			updatedChildPolicy  =  childPolicyName1 
237- 			return  nil 
238- 		},
239- 	})
240- 
241- 	stub .Register (childPolicyName2 , stub.BalancerFuncs {
242- 		UpdateClientConnState : func (_  * stub.BalancerData , _  balancer.ClientConnState ) error  {
243- 			updatedChildPolicy  =  childPolicyName2 
244- 			return  nil 
245- 		},
246- 	})
247- 
248- 	// Initial config update with childPolicyName1 
249- 	if  err  :=  b .UpdateClientConnState (balancer.ClientConnState {
250- 		ResolverState : xdsclient .SetClient (resolver.State {Endpoints : testBackendEndpoints }, xdsC ),
251- 		BalancerConfig : & LBConfig {
252- 			Cluster : testClusterName ,
253- 			ChildPolicy : & internalserviceconfig.BalancerConfig {
254- 				Name : childPolicyName1 ,
255- 			},
256- 		},
257- 	}); err  !=  nil  {
258- 		t .Fatalf ("Error updating the config: %v" , err )
259- 	}
260- 
261- 	if  updatedChildPolicy  !=  childPolicyName1  {
262- 		t .Fatal ("Child policy 1 was not updated on initial configuration update." )
263- 	}
264- 
265- 	// Second config update with childPolicyName2 
266- 	if  err  :=  b .UpdateClientConnState (balancer.ClientConnState {
267- 		ResolverState : xdsclient .SetClient (resolver.State {Endpoints : testBackendEndpoints }, xdsC ),
268- 		BalancerConfig : & LBConfig {
269- 			Cluster : testClusterName ,
270- 			ChildPolicy : & internalserviceconfig.BalancerConfig {
271- 				Name : childPolicyName2 ,
272- 			},
273- 		},
274- 	}); err  !=  nil  {
275- 		t .Fatalf ("Error updating the config: %v" , err )
276- 	}
277- 
278- 	if  updatedChildPolicy  !=  childPolicyName2  {
279- 		t .Fatal ("Child policy 2 was not updated after child policy name change." )
280- 	}
281- }
282- 
283- // Test verifies that config update fails if child policy config 
284- // failed to parse. 
285- func  (s ) TestFailedToParseChildPolicyConfig (t  * testing.T ) {
286- 	xdsC  :=  fakeclient .NewClient ()
287- 
288- 	builder  :=  balancer .Get (Name )
289- 	cc  :=  testutils .NewBalancerClientConn (t )
290- 	b  :=  builder .Build (cc , balancer.BuildOptions {})
291- 	defer  b .Close ()
292- 
293- 	// Create a stub balancer which fails to ParseConfig. 
294- 	const  parseConfigError  =  "failed to parse config" 
295- 	const  childPolicyName  =  "stubBalancer-FailedToParseChildPolicyConfig" 
296- 	stub .Register (childPolicyName , stub.BalancerFuncs {
297- 		ParseConfig : func (_  json.RawMessage ) (serviceconfig.LoadBalancingConfig , error ) {
298- 			return  nil , errors .New (parseConfigError )
299- 		},
300- 	})
301- 
302- 	err  :=  b .UpdateClientConnState (balancer.ClientConnState {
303- 		ResolverState : xdsclient .SetClient (resolver.State {Endpoints : testBackendEndpoints }, xdsC ),
304- 		BalancerConfig : & LBConfig {
305- 			Cluster : testClusterName ,
306- 			ChildPolicy : & internalserviceconfig.BalancerConfig {
307- 				Name : childPolicyName ,
308- 			},
309- 		},
310- 	})
311- 
312- 	if  err  ==  nil  ||  ! strings .Contains (err .Error (), parseConfigError ) {
313- 		t .Fatalf ("Got error: %v, want error: %s" , err , parseConfigError )
314- 	}
315- }
316- 
317208// Test verify that the case picker is updated synchronously on receipt of 
318209// configuration update. 
319210func  (s ) TestPickerUpdatedSynchronouslyOnConfigUpdate (t  * testing.T ) {
@@ -342,9 +233,6 @@ func (s) TestPickerUpdatedSynchronouslyOnConfigUpdate(t *testing.T) {
342233	}
343234	defer  func () { clientConnUpdateHook  =  origClientConnUpdateHook  }()
344235
345- 	defer  xdsclient .ClearCounterForTesting (testClusterName , testServiceName )
346- 	xdsC  :=  fakeclient .NewClient ()
347- 
348236	builder  :=  balancer .Get (Name )
349237	cc  :=  testutils .NewBalancerClientConn (t )
350238	b  :=  builder .Build (cc , balancer.BuildOptions {})
@@ -362,6 +250,7 @@ func (s) TestPickerUpdatedSynchronouslyOnConfigUpdate(t *testing.T) {
362250		},
363251	})
364252
253+ 	xdsC  :=  fakeclient .NewClient ()
365254	if  err  :=  b .UpdateClientConnState (balancer.ClientConnState {
366255		ResolverState : xdsclient .SetClient (resolver.State {Endpoints : testBackendEndpoints }, xdsC ),
367256		BalancerConfig : & LBConfig {
0 commit comments