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

Method TestResolverAddressesToEndpoints

resolver_test.go:102–145  ·  view source on GitHub ↗

TestResolverAddressesToEndpoints ensures one Endpoint is created for each entry in resolver.State.Addresses automatically.

(t *testing.T)

Source from the content-addressed store, hash-verified

100// TestResolverAddressesToEndpoints ensures one Endpoint is created for each
101// entry in resolver.State.Addresses automatically.
102func (s) TestResolverAddressesToEndpoints(t *testing.T) {
103 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
104 defer cancel()
105
106 const scheme = "testresolveraddressestoendpoints"
107 r := manual.NewBuilderWithScheme(scheme)
108
109 stateCh := make(chan balancer.ClientConnState, 1)
110 bf := stub.BalancerFuncs{
111 UpdateClientConnState: func(_ *stub.BalancerData, ccs balancer.ClientConnState) error {
112 stateCh <- ccs
113 return nil
114 },
115 }
116 balancerName := "stub-balancer-" + scheme
117 stub.Register(balancerName, bf)
118
119 a1 := attributes.New("x", "y")
120 a2 := attributes.New("a", "b")
121 r.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: "addr1", BalancerAttributes: a1}, {Addr: "addr2", BalancerAttributes: a2}}})
122
123 cc, err := NewClient(r.Scheme()+":///",
124 WithTransportCredentials(insecure.NewCredentials()),
125 WithResolvers(r),
126 WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, balancerName)))
127 if err != nil {
128 t.Fatalf("NewClient() failed: %v", err)
129 }
130 cc.Connect()
131 defer cc.Close()
132
133 select {
134 case got := <-stateCh:
135 want := []resolver.Endpoint{
136 {Addresses: []resolver.Address{{Addr: "addr1"}}, Attributes: a1},
137 {Addresses: []resolver.Address{{Addr: "addr2"}}, Attributes: a2},
138 }
139 if diff := cmp.Diff(got.ResolverState.Endpoints, want); diff != "" {
140 t.Errorf("Did not receive expected endpoints. Diff (-got +want):\n%v", diff)
141 }
142 case <-ctx.Done():
143 t.Fatalf("timed out waiting for endpoints")
144 }
145}
146
147// Test ensures one Endpoint is created for each entry in
148// resolver.State.Addresses automatically. The test calls the deprecated

Callers

nothing calls this directly

Calls 15

NewBuilderWithSchemeFunction · 0.92
RegisterFunction · 0.92
NewFunction · 0.92
NewCredentialsFunction · 0.92
WithTransportCredentialsFunction · 0.85
WithResolversFunction · 0.85
WithDefaultServiceConfigFunction · 0.85
InitialStateMethod · 0.80
NewClientFunction · 0.70
SchemeMethod · 0.65
FatalfMethod · 0.65
ConnectMethod · 0.65

Tested by

no test coverage detected