Tests that ExitIdle calls are correctly passed through to the child balancer. It starts a backend and ensures the channel connects to it. The test then stops the backend, making the channel enter IDLE. The test calls Connect on the channel and verifies that the child balancer exits idle.
(t *testing.T)
| 393 | // stops the backend, making the channel enter IDLE. The test calls Connect on |
| 394 | // the channel and verifies that the child balancer exits idle. |
| 395 | func (s) TestExitIdlePassthrough(t *testing.T) { |
| 396 | backend1 := stubserver.StartTestService(t, nil) |
| 397 | defer backend1.Stop() |
| 398 | |
| 399 | mr := manual.NewBuilderWithScheme("e2e-test") |
| 400 | defer mr.Close() |
| 401 | |
| 402 | mr.InitialState(resolver.State{ |
| 403 | Endpoints: []resolver.Endpoint{ |
| 404 | {Addresses: []resolver.Address{{Addr: backend1.Address}}}, |
| 405 | }, |
| 406 | }) |
| 407 | |
| 408 | bf := stub.BalancerFuncs{ |
| 409 | Init: func(bd *stub.BalancerData) { |
| 410 | bd.ChildBalancer = lazy.NewBalancer(bd.ClientConn, bd.BuildOptions, balancer.Get(pickfirst.Name).Build) |
| 411 | }, |
| 412 | ExitIdle: func(bd *stub.BalancerData) { |
| 413 | bd.ChildBalancer.ExitIdle() |
| 414 | }, |
| 415 | ResolverError: func(bd *stub.BalancerData, err error) { |
| 416 | bd.ChildBalancer.ResolverError(err) |
| 417 | }, |
| 418 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 419 | return bd.ChildBalancer.UpdateClientConnState(ccs) |
| 420 | }, |
| 421 | Close: func(bd *stub.BalancerData) { |
| 422 | bd.ChildBalancer.Close() |
| 423 | }, |
| 424 | } |
| 425 | stub.Register(t.Name(), bf) |
| 426 | json := fmt.Sprintf(`{"loadBalancingConfig": [{"%s": {}}]}`, t.Name()) |
| 427 | opts := []grpc.DialOption{ |
| 428 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 429 | grpc.WithDefaultServiceConfig(json), |
| 430 | grpc.WithResolvers(mr), |
| 431 | } |
| 432 | cc, err := grpc.NewClient(mr.Scheme()+":///", opts...) |
| 433 | if err != nil { |
| 434 | t.Fatalf("grpc.NewClient(_) failed: %v", err) |
| 435 | |
| 436 | } |
| 437 | defer cc.Close() |
| 438 | |
| 439 | cc.Connect() |
| 440 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 441 | defer cancel() |
| 442 | testutils.AwaitState(ctx, t, cc, connectivity.Ready) |
| 443 | |
| 444 | // Stopping the active backend should put the channel in IDLE. |
| 445 | backend1.Stop() |
| 446 | testutils.AwaitState(ctx, t, cc, connectivity.Idle) |
| 447 | |
| 448 | // Sending a new backend address should not kick the channel out of IDLE. |
| 449 | // On calling cc.Connect(), the channel should call ExitIdle on the lazy |
| 450 | // balancer which passes through the call to the leaf pickfirst. |
| 451 | backend2 := stubserver.StartTestService(t, nil) |
| 452 | defer backend2.Stop() |
nothing calls this directly
no test coverage detected