Tests the scenario when a resolver produces a list of endpoints followed by a resolver error. The test verifies that the child balancer receives only the good update.
(t *testing.T)
| 298 | // a resolver error. The test verifies that the child balancer receives only the |
| 299 | // good update. |
| 300 | func (s) TestResolverErrorThenGoodUpdate(t *testing.T) { |
| 301 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 302 | defer cancel() |
| 303 | |
| 304 | backend := stubserver.StartTestService(t, nil) |
| 305 | defer backend.Stop() |
| 306 | |
| 307 | childBF := stub.BalancerFuncs{ |
| 308 | Init: func(bd *stub.BalancerData) { |
| 309 | bd.ChildBalancer = balancer.Get(pickfirst.Name).Build(bd.ClientConn, bd.BuildOptions) |
| 310 | }, |
| 311 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 312 | return bd.ChildBalancer.UpdateClientConnState(ccs) |
| 313 | }, |
| 314 | ResolverError: func(bd *stub.BalancerData, err error) { |
| 315 | t.Error("Received unexpected resolver error.") |
| 316 | bd.ChildBalancer.ResolverError(err) |
| 317 | }, |
| 318 | Close: func(bd *stub.BalancerData) { |
| 319 | bd.ChildBalancer.Close() |
| 320 | }, |
| 321 | } |
| 322 | |
| 323 | childBalName := strings.ReplaceAll(strings.ToLower(t.Name())+"_child", "/", "") |
| 324 | stub.Register(childBalName, childBF) |
| 325 | |
| 326 | topLevelBF := stub.BalancerFuncs{ |
| 327 | Init: func(bd *stub.BalancerData) { |
| 328 | bd.ChildBalancer = lazy.NewBalancer(bd.ClientConn, bd.BuildOptions, balancer.Get(childBalName).Build) |
| 329 | }, |
| 330 | ExitIdle: func(*stub.BalancerData) { |
| 331 | t.Log("Ignoring call to ExitIdle to delay lazy child creation until RPC time.") |
| 332 | }, |
| 333 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 334 | return bd.ChildBalancer.UpdateClientConnState(ccs) |
| 335 | }, |
| 336 | Close: func(bd *stub.BalancerData) { |
| 337 | bd.ChildBalancer.Close() |
| 338 | }, |
| 339 | } |
| 340 | |
| 341 | topLevelBalName := strings.ReplaceAll(strings.ToLower(t.Name())+"_top_level", "/", "") |
| 342 | stub.Register(topLevelBalName, topLevelBF) |
| 343 | |
| 344 | json := fmt.Sprintf(`{"loadBalancingConfig": [{%q: {}}]}`, topLevelBalName) |
| 345 | |
| 346 | mr := manual.NewBuilderWithScheme("e2e-test") |
| 347 | defer mr.Close() |
| 348 | |
| 349 | mr.InitialState(resolver.State{ |
| 350 | Endpoints: []resolver.Endpoint{ |
| 351 | {Addresses: []resolver.Address{{Addr: backend.Address}}}, |
| 352 | }, |
| 353 | }) |
| 354 | |
| 355 | opts := []grpc.DialOption{ |
| 356 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 357 | grpc.WithResolvers(mr), |
nothing calls this directly
no test coverage detected