From df74a66335fdbb6b174c93c87b8f70e6dfa5b366 Mon Sep 17 00:00:00 2001 From: spacewander Date: Tue, 8 Oct 2024 11:25:52 +0800 Subject: [PATCH] e2e: retry to solve timeout Signed-off-by: spacewander --- e2e/go.mod | 1 + e2e/go.sum | 2 ++ e2e/tests/consumer.go | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/e2e/go.mod b/e2e/go.mod index a3ef46f9..ac76c319 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -17,6 +17,7 @@ module mosn.io/htnn/e2e go 1.21.5 require ( + github.com/avast/retry-go v3.0.0+incompatible github.com/stretchr/testify v1.9.0 istio.io/client-go v1.21.2 k8s.io/api v0.29.3 diff --git a/e2e/go.sum b/e2e/go.sum index cb71b5f5..16725d69 100644 --- a/e2e/go.sum +++ b/e2e/go.sum @@ -6,6 +6,8 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= +github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0= +github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/e2e/tests/consumer.go b/e2e/tests/consumer.go index ee68d68d..531cdcf8 100644 --- a/e2e/tests/consumer.go +++ b/e2e/tests/consumer.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/avast/retry-go" "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -42,7 +43,20 @@ func init() { suite.Register(suite.Test{ Manifests: []string{"base/httproute.yml"}, Run: func(t *testing.T, suite *suite.Suite) { - rsp, err := suite.Get("/echo", hdrWithKey("rick")) + var rsp *http.Response + var err error + err = retry.Do( + func() error { + rsp, err = suite.Get("/echo", hdrWithKey("rick")) + return err + }, + retry.RetryIf(func(err error) bool { + return true + }), + retry.Attempts(3), + // backoff delay + retry.Delay(500*time.Millisecond), + ) require.NoError(t, err) require.Equal(t, 200, rsp.StatusCode) req, _, err := suite.Capture(rsp)