1
0
Fork 0

Feature: Exponential Backoff in Retry Middleware

This commit is contained in:
Daniel Adams 2020-11-05 10:14:04 -05:00 committed by GitHub
parent 3a8cb3f010
commit 74d1d55051
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 218 additions and 44 deletions

View file

@ -9,10 +9,12 @@ import (
"strconv"
"strings"
"testing"
"time"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
ptypes "github.com/traefik/paerser/types"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
"github.com/traefik/traefik/v2/pkg/middlewares/emptybackendhandler"
"github.com/traefik/traefik/v2/pkg/testhelpers"
@ -35,6 +37,13 @@ func TestRetry(t *testing.T) {
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 0,
},
{
desc: "no retry on success with backoff",
config: dynamic.Retry{Attempts: 1, InitialInterval: ptypes.Duration(time.Microsecond * 50)},
wantRetryAttempts: 0,
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 0,
},
{
desc: "no retry when max request attempts is one",
config: dynamic.Retry{Attempts: 1},
@ -42,6 +51,13 @@ func TestRetry(t *testing.T) {
wantResponseStatus: http.StatusBadGateway,
amountFaultyEndpoints: 1,
},
{
desc: "no retry when max request attempts is one with backoff",
config: dynamic.Retry{Attempts: 1, InitialInterval: ptypes.Duration(time.Microsecond * 50)},
wantRetryAttempts: 0,
wantResponseStatus: http.StatusBadGateway,
amountFaultyEndpoints: 1,
},
{
desc: "one retry when one server is faulty",
config: dynamic.Retry{Attempts: 2},
@ -49,6 +65,13 @@ func TestRetry(t *testing.T) {
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 1,
},
{
desc: "one retry when one server is faulty with backoff",
config: dynamic.Retry{Attempts: 2, InitialInterval: ptypes.Duration(time.Microsecond * 50)},
wantRetryAttempts: 1,
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 1,
},
{
desc: "two retries when two servers are faulty",
config: dynamic.Retry{Attempts: 3},
@ -56,6 +79,13 @@ func TestRetry(t *testing.T) {
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 2,
},
{
desc: "two retries when two servers are faulty with backoff",
config: dynamic.Retry{Attempts: 3, InitialInterval: ptypes.Duration(time.Microsecond * 50)},
wantRetryAttempts: 2,
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 2,
},
{
desc: "max attempts exhausted delivers the 5xx response",
config: dynamic.Retry{Attempts: 3},
@ -63,6 +93,13 @@ func TestRetry(t *testing.T) {
wantResponseStatus: http.StatusBadGateway,
amountFaultyEndpoints: 3,
},
{
desc: "max attempts exhausted delivers the 5xx response with backoff",
config: dynamic.Retry{Attempts: 3, InitialInterval: ptypes.Duration(time.Microsecond * 50)},
wantRetryAttempts: 2,
wantResponseStatus: http.StatusBadGateway,
amountFaultyEndpoints: 3,
},
}
backendServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {