Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a3f532c8d |
+18
-10
@@ -897,23 +897,31 @@ func TestGetHonorsRetryAfter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetStopsWaitingWhenCanceled gives get a server that always answers
|
||||
// 503 and an hour's wait before each retry, then lets the context expire
|
||||
// during that wait. get returning at all shows it stopped waiting.
|
||||
// instant503Transport answers every request with a 503 at once, so the
|
||||
// 503 is in hand before any deadline can pass.
|
||||
type instant503Transport struct{}
|
||||
|
||||
func (instant503Transport) RoundTrip(*http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusServiceUnavailable,
|
||||
Body: http.NoBody,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TestGetStopsWaitingWhenCanceled answers every request with a 503 and
|
||||
// sets an hour's wait before each retry, then lets the context expire
|
||||
// during that wait. get returning at all shows it stopped waiting; it must
|
||||
// return the deadline error and keep the 503 with it.
|
||||
func TestGetStopsWaitingWhenCanceled(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
server := httptest.NewServer(
|
||||
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := testClient()
|
||||
client.client.Transport = instant503Transport{}
|
||||
client.firstDelay = time.Hour
|
||||
|
||||
err := getNothing(client, server.URL, 50*time.Millisecond)
|
||||
err := getNothing(client, "http://example.invalid/", 50*time.Millisecond)
|
||||
require.ErrorIs(t, err, context.DeadlineExceeded)
|
||||
require.ErrorIs(t, err, errHTTPStatus)
|
||||
}
|
||||
|
||||
// late503Transport answers every request with a 503, but only once the
|
||||
|
||||
Reference in New Issue
Block a user