MCPcopy Index your code
hub / github.com/labstack/echo / TestProxyRetries

Function TestProxyRetries

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

Source from the content-addressed store, hash-verified

553}
554
555func TestProxyRetries(t *testing.T) {
556 newServer := func(res int) (*url.URL, *httptest.Server) {
557 server := httptest.NewServer(
558 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
559 w.WriteHeader(res)
560 }),
561 )
562 targetURL, _ := url.Parse(server.URL)
563 return targetURL, server
564 }
565
566 targetURL, server := newServer(http.StatusOK)
567 defer server.Close()
568 goodTarget := &ProxyTarget{
569 Name: "Good",
570 URL: targetURL,
571 }
572
573 targetURL, server = newServer(http.StatusBadRequest)
574 defer server.Close()
575 goodTargetWith40X := &ProxyTarget{
576 Name: "Good with 40X",
577 URL: targetURL,
578 }
579
580 targetURL, _ = url.Parse("http://127.0.0.1:27121")
581 badTarget := &ProxyTarget{
582 Name: "Bad",
583 URL: targetURL,
584 }
585
586 alwaysRetryFilter := func(c *echo.Context, e error) bool { return true }
587 neverRetryFilter := func(c *echo.Context, e error) bool { return false }
588
589 testCases := []struct {
590 name string
591 retryCount int
592 retryFilters []func(c *echo.Context, e error) bool
593 targets []*ProxyTarget
594 expectedResponse int
595 }{
596 {
597 name: "retry count 0 does not attempt retry on fail",
598 targets: []*ProxyTarget{
599 badTarget,
600 goodTarget,
601 },
602 expectedResponse: http.StatusBadGateway,
603 },
604 {
605 name: "retry count 1 does not attempt retry on success",
606 retryCount: 1,
607 targets: []*ProxyTarget{
608 goodTarget,
609 },
610 expectedResponse: http.StatusOK,
611 },
612 {

Callers

nothing calls this directly

Calls 6

ProxyWithConfigFunction · 0.85
NewRoundRobinBalancerFunction · 0.85
ServeHTTPMethod · 0.80
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…