From 3efdc7f5fc0b07dd6a44dfb93092256f18e6bb64 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Wed, 16 Sep 2020 07:20:21 +0200 Subject: [PATCH] fixup! fix: increase code coverage Signed-off-by: Yoan Blanc --- httpclient/client.go | 56 ++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/httpclient/client.go b/httpclient/client.go index 52ec0e7..d4c818c 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -157,52 +157,32 @@ outter: if err != nil { multiErr.Push(err.Error()) c.reportError(request, err) - - backoffTime := c.retrier.NextInterval(i) - ctx, cancel := context.WithTimeout(context.Background(), backoffTime) - - select { - case <-ctx.Done(): - cancel() - - continue - - case <-request.Context().Done(): - cancel() - - multiErr.Push(request.Context().Err().Error()) - c.reportError(request, request.Context().Err()) - - // If the request context has already been cancelled, don't retry - break outter - } + } else { + c.reportRequestEnd(request, response) } - c.reportRequestEnd(request, response) - - if response.StatusCode >= http.StatusInternalServerError { - backoffTime := c.retrier.NextInterval(i) - ctx, cancel := context.WithTimeout(context.Background(), backoffTime) + if err == nil && response.StatusCode < http.StatusInternalServerError { + // Clear errors if any iteration succeeds + multiErr = &valkyrie.MultiError{} + break + } - select { - case <-ctx.Done(): - cancel() + backoffTime := c.retrier.NextInterval(i) + ctx, cancel := context.WithTimeout(context.Background(), backoffTime) - continue + select { + case <-ctx.Done(): + cancel() - case <-request.Context().Done(): - cancel() + case <-request.Context().Done(): + cancel() - multiErr.Push(request.Context().Err().Error()) - c.reportError(request, request.Context().Err()) + multiErr.Push(request.Context().Err().Error()) + c.reportError(request, request.Context().Err()) - // If the request context has already been cancelled, don't retry - break outter - } + // If the request context has already been cancelled, don't retry + break outter } - - multiErr = &valkyrie.MultiError{} // Clear errors if any iteration succeeds - break } return response, multiErr.HasError()