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

Method TestResetConnectBackoff

clientconn_test.go:609–646  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

607func (b backoffForever) Backoff(int) time.Duration { return time.Duration(math.MaxInt64) }
608
609func (s) TestResetConnectBackoff(t *testing.T) {
610 dials := make(chan struct{})
611 defer func() { // If we fail, let the http2client break out of dialing.
612 select {
613 case <-dials:
614 default:
615 }
616 }()
617 dialer := func(string, time.Duration) (net.Conn, error) {
618 dials <- struct{}{}
619 return nil, errors.New("failed to fake dial")
620 }
621 cc, err := NewClient("passthrough:///", WithTransportCredentials(insecure.NewCredentials()), WithDialer(dialer), withBackoff(backoffForever{}))
622 if err != nil {
623 t.Fatalf("grpc.NewClient() failed with error: %v, want: nil", err)
624 }
625 defer cc.Close()
626 go stayConnected(cc)
627 select {
628 case <-dials:
629 case <-time.NewTimer(10 * time.Second).C:
630 t.Fatal("Failed to call dial within 10s")
631 }
632
633 select {
634 case <-dials:
635 t.Fatal("Dial called unexpectedly before resetting backoff")
636 case <-time.NewTimer(100 * time.Millisecond).C:
637 }
638
639 cc.ResetConnectBackoff()
640
641 select {
642 case <-dials:
643 case <-time.NewTimer(10 * time.Second).C:
644 t.Fatal("Failed to call dial within 10s after resetting backoff")
645 }
646}
647
648func (s) TestBackoffCancel(t *testing.T) {
649 dialStrCh := make(chan string)

Callers

nothing calls this directly

Calls 11

NewCredentialsFunction · 0.92
WithTransportCredentialsFunction · 0.85
WithDialerFunction · 0.85
withBackoffFunction · 0.85
stayConnectedFunction · 0.85
NewTimerMethod · 0.80
ResetConnectBackoffMethod · 0.80
NewClientFunction · 0.70
FatalfMethod · 0.65
CloseMethod · 0.65
FatalMethod · 0.65

Tested by

no test coverage detected