When creating a transport configured with n addresses, only calculate the backoff once per "round" of attempts instead of once per address (n times per "round" of attempts) for old pickfirst and once per address for new pickfirst.
(t *testing.T)
| 259 | // backoff once per "round" of attempts instead of once per address (n times |
| 260 | // per "round" of attempts) for old pickfirst and once per address for new pickfirst. |
| 261 | func (s) TestNewClient_BackoffCountPerRetryGroup(t *testing.T) { |
| 262 | var attempts uint32 |
| 263 | wantBackoffs := uint32(2) |
| 264 | getMinConnectTimeout := func() time.Duration { |
| 265 | if atomic.AddUint32(&attempts, 1) <= wantBackoffs { |
| 266 | // Once all addresses are exhausted, hang around and wait for the |
| 267 | // client.Close to happen rather than re-starting a new round of |
| 268 | // attempts. |
| 269 | return time.Hour |
| 270 | } |
| 271 | t.Errorf("only %d attempt backoff calculation, but got more", wantBackoffs) |
| 272 | return 0 |
| 273 | } |
| 274 | |
| 275 | lis1, err := net.Listen("tcp", "localhost:0") |
| 276 | if err != nil { |
| 277 | t.Fatalf("Error while listening. Err: %v", err) |
| 278 | } |
| 279 | defer lis1.Close() |
| 280 | |
| 281 | lis2, err := net.Listen("tcp", "localhost:0") |
| 282 | if err != nil { |
| 283 | t.Fatalf("Error while listening. Err: %v", err) |
| 284 | } |
| 285 | defer lis2.Close() |
| 286 | |
| 287 | server1Done := make(chan struct{}) |
| 288 | server2Done := make(chan struct{}) |
| 289 | |
| 290 | // Launch server 1. |
| 291 | go func() { |
| 292 | conn, err := lis1.Accept() |
| 293 | if err != nil { |
| 294 | t.Error(err) |
| 295 | return |
| 296 | } |
| 297 | |
| 298 | conn.Close() |
| 299 | close(server1Done) |
| 300 | }() |
| 301 | // Launch server 2. |
| 302 | go func() { |
| 303 | conn, err := lis2.Accept() |
| 304 | if err != nil { |
| 305 | t.Error(err) |
| 306 | return |
| 307 | } |
| 308 | conn.Close() |
| 309 | close(server2Done) |
| 310 | }() |
| 311 | |
| 312 | rb := manual.NewBuilderWithScheme("whatever") |
| 313 | rb.InitialState(resolver.State{Addresses: []resolver.Address{ |
| 314 | {Addr: lis1.Addr().String()}, |
| 315 | {Addr: lis2.Addr().String()}, |
| 316 | }}) |
| 317 | client, err := NewClient("whatever:///this-gets-overwritten", |
| 318 | WithTransportCredentials(insecure.NewCredentials()), |
nothing calls this directly
no test coverage detected