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

Method TestResolverAddressesToEndpointsUsingNewAddresses

resolver_test.go:150–197  ·  view source on GitHub ↗

Test ensures one Endpoint is created for each entry in resolver.State.Addresses automatically. The test calls the deprecated NewAddresses API to send a list of addresses to the channel.

(t *testing.T)

Source from the content-addressed store, hash-verified

148// resolver.State.Addresses automatically. The test calls the deprecated
149// NewAddresses API to send a list of addresses to the channel.
150func (s) TestResolverAddressesToEndpointsUsingNewAddresses(t *testing.T) {
151 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
152 defer cancel()
153
154 const scheme = "testresolveraddressestoendpoints"
155 r := manual.NewBuilderWithScheme(scheme)
156
157 stateCh := make(chan balancer.ClientConnState, 1)
158 bf := stub.BalancerFuncs{
159 UpdateClientConnState: func(_ *stub.BalancerData, ccs balancer.ClientConnState) error {
160 stateCh <- ccs
161 return nil
162 },
163 }
164 balancerName := "stub-balancer-" + scheme
165 stub.Register(balancerName, bf)
166
167 a1 := attributes.New("x", "y")
168 a2 := attributes.New("a", "b")
169 addrs := []resolver.Address{
170 {Addr: "addr1", BalancerAttributes: a1},
171 {Addr: "addr2", BalancerAttributes: a2},
172 }
173
174 cc, err := NewClient(r.Scheme()+":///",
175 WithTransportCredentials(insecure.NewCredentials()),
176 WithResolvers(r),
177 WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, balancerName)))
178 if err != nil {
179 t.Fatalf("NewClient() failed: %v", err)
180 }
181 cc.Connect()
182 defer cc.Close()
183 r.CC().NewAddress(addrs)
184
185 select {
186 case got := <-stateCh:
187 want := []resolver.Endpoint{
188 {Addresses: []resolver.Address{{Addr: "addr1"}}, Attributes: a1},
189 {Addresses: []resolver.Address{{Addr: "addr2"}}, Attributes: a2},
190 }
191 if diff := cmp.Diff(got.ResolverState.Endpoints, want); diff != "" {
192 t.Errorf("Did not receive expected endpoints. Diff (-got +want):\n%v", diff)
193 }
194 case <-ctx.Done():
195 t.Fatalf("timed out waiting for endpoints")
196 }
197}

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
CCMethod · 0.80
NewClientFunction · 0.70
SchemeMethod · 0.65
FatalfMethod · 0.65
ConnectMethod · 0.65

Tested by

no test coverage detected