MCPcopy
hub / github.com/grpc/grpc-go / TestExitIdle

Method TestExitIdle

balancer/lazy/lazy_ext_test.go:67–134  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

65// calls Connect() on the channel which in turn calls ExitIdle on the lazy
66// balancer. The test verifies that the channel enters READY.
67func (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 })

Callers

nothing calls this directly

Calls 15

EmptyCallMethod · 0.95
StartTestServiceFunction · 0.92
NewBuilderWithSchemeFunction · 0.92
NewBalancerFunction · 0.92
GetFunction · 0.92
RegisterFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
WithDefaultServiceConfigFunction · 0.92
WithResolversFunction · 0.92
NewClientFunction · 0.92
AwaitStateFunction · 0.92

Tested by

no test coverage detected