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)
| 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. |
| 249 | func (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 |
nothing calls this directly
no test coverage detected