MCPcopy Create free account
hub / github.com/imroc/req / TestAddRetryCondition

Function TestAddRetryCondition

retry_test.go:83–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestAddRetryCondition(t *testing.T) {
84 attempt := 0
85 resp, err := tc().R().
86 SetRetryCount(3).
87 AddRetryCondition(func(resp *Response, err error) bool {
88 return err != nil
89 }).
90 AddRetryCondition(func(resp *Response, err error) bool {
91 return resp.StatusCode == http.StatusServiceUnavailable
92 }).
93 SetRetryHook(func(resp *Response, err error) {
94 attempt++
95 }).Get("/too-many")
96 tests.AssertNoError(t, err)
97 tests.AssertEqual(t, 0, attempt)
98 tests.AssertEqual(t, 0, resp.Request.RetryAttempt)
99
100 attempt = 0
101 resp, err = tc().
102 SetCommonRetryCount(3).
103 AddCommonRetryCondition(func(resp *Response, err error) bool {
104 return err != nil
105 }).
106 AddCommonRetryCondition(func(resp *Response, err error) bool {
107 return resp.StatusCode == http.StatusServiceUnavailable
108 }).
109 SetCommonRetryHook(func(resp *Response, err error) {
110 attempt++
111 }).R().Get("/too-many")
112 tests.AssertNoError(t, err)
113 tests.AssertEqual(t, 0, attempt)
114 tests.AssertEqual(t, 0, resp.Request.RetryAttempt)
115
116}
117
118func TestRetryWithUnreplayableBody(t *testing.T) {
119 _, err := tc().R().

Callers

nothing calls this directly

Calls 11

AssertNoErrorFunction · 0.92
AssertEqualFunction · 0.92
tcFunction · 0.85
SetRetryHookMethod · 0.80
AddRetryConditionMethod · 0.80
SetRetryCountMethod · 0.80
RMethod · 0.80
SetCommonRetryHookMethod · 0.80
SetCommonRetryCountMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…