-
Notifications
You must be signed in to change notification settings - Fork 0
Adds retries to 404 requests #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,7 +148,32 @@ func TestWithRetries_failingBadStatusCode_validateSleeps(t *testing.T) { | |
| } | ||
|
|
||
| func TestWithRetries_healingServer(t *testing.T) { | ||
| srv := httptest.NewServer(new(healingServer)) | ||
| h := &healingServer{ | ||
| HealAfter: 4, | ||
| FailCode: 500, | ||
| SuccessCode: 200, | ||
| } | ||
|
Comment on lines
+151
to
+155
|
||
| srv := httptest.NewServer(h) | ||
| defer srv.Close() | ||
|
|
||
| d := NewTestURLRequest(srv.URL) | ||
| rm := requesthelper.GetRequestManager(d, testRequestTimeout) | ||
| sr := new(sleepRecorder) | ||
| resp, err := requesthelper.WithRetries(nopLog(), rm, sr.Sleep) | ||
| defer resp.Body.Close() | ||
| require.Nil(t, err, "should eventually succeed") | ||
| require.NotNil(t, resp.Body, "response body exists") | ||
jscalev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| require.Equal(t, sleepSchedule[:3], []time.Duration(*sr)) | ||
| } | ||
|
|
||
| func TestWithRetries_retry404(t *testing.T) { | ||
| h := &healingServer{ | ||
| HealAfter: 4, | ||
| FailCode: 404, | ||
| SuccessCode: 200, | ||
| } | ||
| srv := httptest.NewServer(h) | ||
|
Comment on lines
+170
to
+176
|
||
| defer srv.Close() | ||
|
|
||
| d := NewTestURLRequest(srv.URL) | ||
|
|
@@ -173,14 +198,19 @@ func (s *sleepRecorder) Sleep(d time.Duration) { | |
| } | ||
|
|
||
| // healingServer returns HTTP 500 until 4th call, then HTTP 200 afterwards | ||
| type healingServer int | ||
| type healingServer struct { | ||
| calls int | ||
| HealAfter int // number of calls that must happen before we start succeeding | ||
| FailCode int | ||
| SuccessCode int | ||
jscalev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| func (h *healingServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
| *h++ | ||
| if *h < 4 { | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
| h.calls++ | ||
| if h.calls < h.HealAfter { | ||
| w.WriteHeader(h.FailCode) | ||
| } else { | ||
| w.WriteHeader(http.StatusOK) | ||
| w.WriteHeader(h.SuccessCode) | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.