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

Method TestNewClient_BackoffCountPerRetryGroup

clientconn_test.go:261–343  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
261func (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()),

Callers

nothing calls this directly

Calls 15

NewBuilderWithSchemeFunction · 0.92
NewCredentialsFunction · 0.92
WithTransportCredentialsFunction · 0.85
WithResolversFunction · 0.85
withMinConnectDeadlineFunction · 0.85
InitialStateMethod · 0.80
NewClientFunction · 0.70
ErrorfMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected