Skip to content

Commit 3e29c94

Browse files
authored
e2e: retry to solve timeout (#759)
Signed-off-by: spacewander <[email protected]>
1 parent 6a77468 commit 3e29c94

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

e2e/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module mosn.io/htnn/e2e
1717
go 1.21.5
1818

1919
require (
20+
github.com/avast/retry-go v3.0.0+incompatible
2021
github.com/stretchr/testify v1.9.0
2122
istio.io/client-go v1.21.2
2223
k8s.io/api v0.29.3

e2e/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRB
88
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
99
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
1010
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
11+
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
12+
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
1113
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1214
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
1315
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=

e2e/tests/consumer.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/avast/retry-go"
2425
"github.com/stretchr/testify/require"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/runtime"
@@ -42,7 +43,20 @@ func init() {
4243
suite.Register(suite.Test{
4344
Manifests: []string{"base/httproute.yml"},
4445
Run: func(t *testing.T, suite *suite.Suite) {
45-
rsp, err := suite.Get("/echo", hdrWithKey("rick"))
46+
var rsp *http.Response
47+
var err error
48+
err = retry.Do(
49+
func() error {
50+
rsp, err = suite.Get("/echo", hdrWithKey("rick"))
51+
return err
52+
},
53+
retry.RetryIf(func(err error) bool {
54+
return true
55+
}),
56+
retry.Attempts(3),
57+
// backoff delay
58+
retry.Delay(500*time.Millisecond),
59+
)
4660
require.NoError(t, err)
4761
require.Equal(t, 200, rsp.StatusCode)
4862
req, _, err := suite.Capture(rsp)

0 commit comments

Comments
 (0)