MCPcopy
hub / github.com/labstack/echo / TestProxyRetryWithBackendTimeout

Function TestProxyRetryWithBackendTimeout

middleware/proxy_test.go:733–785  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

731}
732
733func 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
787func TestProxyErrorHandler(t *testing.T) {
788

Callers

nothing calls this directly

Calls 7

ProxyWithConfigFunction · 0.85
NewRoundRobinBalancerFunction · 0.85
ServeHTTPMethod · 0.80
CloneMethod · 0.45
WriteHeaderMethod · 0.45
CloseMethod · 0.45
UseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…