mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-29 17:44:30 -04:00
Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
40 lines
1.8 KiB
Go
40 lines
1.8 KiB
Go
package failover
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
"google.golang.org/grpc/codes"
|
|
grpcstatus "google.golang.org/grpc/status"
|
|
)
|
|
|
|
var _ = DescribeTable("IsRetryable",
|
|
func(err error, status int, want bool) {
|
|
Expect(IsRetryable(err, status)).To(Equal(want))
|
|
},
|
|
Entry("nil error, no status", nil, 0, false),
|
|
Entry("held 503", nil, http.StatusServiceUnavailable, true),
|
|
Entry("held 500", nil, http.StatusInternalServerError, true),
|
|
Entry("held 501", nil, http.StatusNotImplemented, false),
|
|
Entry("client cancel", context.Canceled, 0, false),
|
|
Entry("wrapped client cancel", fmt.Errorf("predict: %w", context.Canceled), 0, false),
|
|
Entry("deadline", context.DeadlineExceeded, 0, true),
|
|
Entry("echo 502", echo.NewHTTPError(http.StatusBadGateway, "x"), 0, true),
|
|
Entry("echo 400", echo.NewHTTPError(http.StatusBadRequest, "x"), 0, false),
|
|
Entry("echo 404", echo.NewHTTPError(http.StatusNotFound, "x"), 0, false),
|
|
Entry("grpc unavailable", grpcstatus.Error(codes.Unavailable, "x"), 0, true),
|
|
Entry("grpc internal", grpcstatus.Error(codes.Internal, "x"), 0, true),
|
|
Entry("grpc deadline", grpcstatus.Error(codes.DeadlineExceeded, "x"), 0, true),
|
|
Entry("grpc unknown", grpcstatus.Error(codes.Unknown, "x"), 0, true),
|
|
Entry("grpc invalid argument", grpcstatus.Error(codes.InvalidArgument, "x"), 0, false),
|
|
Entry("cloud-proxy upstream 503", errors.New("cloud-proxy: upstream 503: no healthy nodes"), 0, true),
|
|
Entry("cloud-proxy upstream 429 stays 4xx", errors.New("cloud-proxy: upstream 429: slow down"), 0, false),
|
|
Entry("context overflow", errors.New("the request exceeds the available context size"), 0, false),
|
|
Entry("dial error", errors.New("dial tcp 10.0.0.1:8080: connect: connection refused"), 0, true),
|
|
)
|