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

Method TestPickFirst_AddressesRemoved

balancer/pickfirst/pickfirst_ext_test.go:249–288  ·  view source on GitHub ↗

TestPickFirst_AddressesRemoved tests the scenario where we have multiple backends and pick_first is working as expected. It then verifies that when addresses are removed by the name resolver, RPCs get routed appropriately.

(t *testing.T)

Source from the content-addressed store, hash-verified

247// backends and pick_first is working as expected. It then verifies that when
248// addresses are removed by the name resolver, RPCs get routed appropriately.
249func (s) TestPickFirst_AddressesRemoved(t *testing.T) {
250 cc, r, backends := setupPickFirst(t, 3)
251
252 addrs := stubBackendsToResolverAddrs(backends)
253 r.UpdateState(resolver.State{Addresses: addrs})
254
255 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
256 defer cancel()
257 if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[0]); err != nil {
258 t.Fatal(err)
259 }
260
261 // Remove the first backend from the list of addresses originally pushed.
262 // RPCs should get routed to the first backend in the new list.
263 r.UpdateState(resolver.State{Addresses: []resolver.Address{addrs[1], addrs[2]}})
264 if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[1]); err != nil {
265 t.Fatal(err)
266 }
267
268 // Append the backend that we just removed to the end of the list.
269 // Nothing should change.
270 r.UpdateState(resolver.State{Addresses: []resolver.Address{addrs[1], addrs[2], addrs[0]}})
271 if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[1]); err != nil {
272 t.Fatal(err)
273 }
274
275 // Remove the first backend from the existing list of addresses.
276 // RPCs should get routed to the first backend in the new list.
277 r.UpdateState(resolver.State{Addresses: []resolver.Address{addrs[2], addrs[0]}})
278 if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[2]); err != nil {
279 t.Fatal(err)
280 }
281
282 // Remove the first backend from the existing list of addresses.
283 // RPCs should get routed to the first backend in the new list.
284 r.UpdateState(resolver.State{Addresses: []resolver.Address{addrs[0]}})
285 if err := pickfirst.CheckRPCsToBackend(ctx, cc, addrs[0]); err != nil {
286 t.Fatal(err)
287 }
288}
289
290// TestPickFirst_NewAddressWhileBlocking tests the case where pick_first is
291// configured on a channel, things are working as expected and then a resolver

Callers

nothing calls this directly

Calls 5

CheckRPCsToBackendFunction · 0.92
setupPickFirstFunction · 0.85
UpdateStateMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected