Return the context's error when it ends during a fetch request (closes #221)
check / check (push) Waiting to run
check / check (push) Waiting to run
retryingClient.get checked its context right after each request and returned that request's error, so a deadline that passed while a 503 was on its way came back as the 503. TestGetStopsWaitingWhenCanceled failed on that now and then on a loaded host. When the context ends before a retry, during the request or during the wait, get now returns an error wrapping both the context's error and the last try's error. The new test answers through a transport that holds the 503 until the context has ended. A real server cannot do that: the client drops a response still on its way when the context ends. Model: opus-5-5
This commit is contained in:
@@ -916,6 +916,34 @@ func TestGetStopsWaitingWhenCanceled(t *testing.T) {
|
||||
require.ErrorIs(t, err, context.DeadlineExceeded)
|
||||
}
|
||||
|
||||
// late503Transport answers every request with a 503, but only once the
|
||||
// request's context has ended. A real server cannot stand in for it: the
|
||||
// client drops a response still on its way when the context ends.
|
||||
type late503Transport struct{}
|
||||
|
||||
func (late503Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
<-req.Context().Done()
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusServiceUnavailable,
|
||||
Body: http.NoBody,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TestGetStopsWhenContextEndsDuringRequest lets the context expire while
|
||||
// the first request is still waiting for its 503. get must return the
|
||||
// deadline error and keep the 503 with it.
|
||||
func TestGetStopsWhenContextEndsDuringRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client := testClient()
|
||||
client.client.Transport = late503Transport{}
|
||||
|
||||
err := getNothing(client, "http://example.invalid/", 50*time.Millisecond)
|
||||
require.ErrorIs(t, err, context.DeadlineExceeded)
|
||||
require.ErrorIs(t, err, errHTTPStatus)
|
||||
}
|
||||
|
||||
// TestDownloadFileRetriesToSuccess serves a file that fails twice before
|
||||
// it succeeds: first with a 503, then with a body cut off halfway. The
|
||||
// download must end with the whole, verified file and no temp file.
|
||||
|
||||
Reference in New Issue
Block a user