-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttpc_issues_test.go
45 lines (38 loc) · 991 Bytes
/
httpc_issues_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package httpc
import (
"errors"
"net/http"
"testing"
"time"
"gopkg.in/h2non/gock.v1"
)
// Too many retries leads to... success
// https://github.com/fako1024/httpc/issues/43
func TestIssue43FailedRetriesLeadToSuccedd(t *testing.T) {
uri := joinURI(httpsEndpoint, "issue_43")
// Set up a mock matcher
g := gock.New(uri)
g.Persist().
Get("/").
Reply(http.StatusInternalServerError)
req := New(http.MethodGet, uri).
RetryBackOffErrFn(func(resp *http.Response, err error) bool {
if resp == nil || err != nil {
return true
}
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
return false
}
return true
}).
RetryBackOff(Intervals{time.Millisecond, time.Millisecond, time.Millisecond})
gock.InterceptClient(req.client)
defer gock.RestoreClient(req.client)
err := req.Run()
if err == nil {
t.Fatal("expected error, got none")
}
if !errors.Is(err, ErrRetryLimit) {
t.Fatalf("unexpected error, want %s, have %s", ErrRetryLimit, err)
}
}