(t *testing.T)
| 731 | } |
| 732 | |
| 733 | func TestProxyRetryWithBackendTimeout(t *testing.T) { |
| 734 | |
| 735 | transport := http.DefaultTransport.(*http.Transport).Clone() |
| 736 | transport.ResponseHeaderTimeout = time.Millisecond * 500 |
| 737 | |
| 738 | timeoutBackend := httptest.NewServer( |
| 739 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 740 | time.Sleep(1 * time.Second) |
| 741 | w.WriteHeader(404) |
| 742 | }), |
| 743 | ) |
| 744 | defer timeoutBackend.Close() |
| 745 | |
| 746 | timeoutTargetURL, _ := url.Parse(timeoutBackend.URL) |
| 747 | goodBackend := httptest.NewServer( |
| 748 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 749 | w.WriteHeader(200) |
| 750 | }), |
| 751 | ) |
| 752 | defer goodBackend.Close() |
| 753 | |
| 754 | goodTargetURL, _ := url.Parse(goodBackend.URL) |
| 755 | e := echo.New() |
| 756 | e.Use(ProxyWithConfig( |
| 757 | ProxyConfig{ |
| 758 | Transport: transport, |
| 759 | Balancer: NewRoundRobinBalancer([]*ProxyTarget{ |
| 760 | { |
| 761 | Name: "Timeout", |
| 762 | URL: timeoutTargetURL, |
| 763 | }, |
| 764 | { |
| 765 | Name: "Good", |
| 766 | URL: goodTargetURL, |
| 767 | }, |
| 768 | }), |
| 769 | RetryCount: 1, |
| 770 | }, |
| 771 | )) |
| 772 | |
| 773 | var wg sync.WaitGroup |
| 774 | for range 20 { |
| 775 | wg.Go(func() { |
| 776 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 777 | rec := httptest.NewRecorder() |
| 778 | e.ServeHTTP(rec, req) |
| 779 | assert.Equal(t, 200, rec.Code) |
| 780 | }) |
| 781 | } |
| 782 | |
| 783 | wg.Wait() |
| 784 | |
| 785 | } |
| 786 | |
| 787 | func TestProxyErrorHandler(t *testing.T) { |
| 788 |
nothing calls this directly
no test coverage detected
searching dependent graphs…