TestExitIdle creates a lazy balancer than manages a pickfirst child. The test calls Connect() on the channel which in turn calls ExitIdle on the lazy balancer. The test verifies that the channel enters READY.
(t *testing.T)
| 65 | // calls Connect() on the channel which in turn calls ExitIdle on the lazy |
| 66 | // balancer. The test verifies that the channel enters READY. |
| 67 | func (s) TestExitIdle(t *testing.T) { |
| 68 | backend1 := stubserver.StartTestService(t, nil) |
| 69 | defer backend1.Stop() |
| 70 | |
| 71 | mr := manual.NewBuilderWithScheme("e2e-test") |
| 72 | defer mr.Close() |
| 73 | |
| 74 | mr.InitialState(resolver.State{ |
| 75 | Endpoints: []resolver.Endpoint{ |
| 76 | {Addresses: []resolver.Address{{Addr: backend1.Address}}}, |
| 77 | }, |
| 78 | }) |
| 79 | |
| 80 | bf := stub.BalancerFuncs{ |
| 81 | Init: func(bd *stub.BalancerData) { |
| 82 | bd.ChildBalancer = lazy.NewBalancer(bd.ClientConn, bd.BuildOptions, balancer.Get(pickfirst.Name).Build) |
| 83 | }, |
| 84 | ExitIdle: func(bd *stub.BalancerData) { |
| 85 | bd.ChildBalancer.ExitIdle() |
| 86 | }, |
| 87 | ResolverError: func(bd *stub.BalancerData, err error) { |
| 88 | bd.ChildBalancer.ResolverError(err) |
| 89 | }, |
| 90 | UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { |
| 91 | return bd.ChildBalancer.UpdateClientConnState(ccs) |
| 92 | }, |
| 93 | Close: func(bd *stub.BalancerData) { |
| 94 | bd.ChildBalancer.Close() |
| 95 | }, |
| 96 | } |
| 97 | stub.Register(t.Name(), bf) |
| 98 | json := fmt.Sprintf(`{"loadBalancingConfig": [{"%s": {}}]}`, t.Name()) |
| 99 | opts := []grpc.DialOption{ |
| 100 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 101 | grpc.WithDefaultServiceConfig(json), |
| 102 | grpc.WithResolvers(mr), |
| 103 | } |
| 104 | cc, err := grpc.NewClient(mr.Scheme()+":///", opts...) |
| 105 | if err != nil { |
| 106 | t.Fatalf("grpc.NewClient(_) failed: %v", err) |
| 107 | } |
| 108 | defer cc.Close() |
| 109 | |
| 110 | cc.Connect() |
| 111 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 112 | defer cancel() |
| 113 | testutils.AwaitState(ctx, t, cc, connectivity.Ready) |
| 114 | |
| 115 | // Send a resolver update to verify that the resolver state is correctly |
| 116 | // passed through to the leaf pickfirst balancer. |
| 117 | backend2 := stubserver.StartTestService(t, nil) |
| 118 | defer backend2.Stop() |
| 119 | |
| 120 | mr.UpdateState(resolver.State{ |
| 121 | Endpoints: []resolver.Endpoint{ |
| 122 | {Addresses: []resolver.Address{{Addr: backend2.Address}}}, |
| 123 | }, |
| 124 | }) |
nothing calls this directly
no test coverage detected