heimdall icon indicating copy to clipboard operation
heimdall copied to clipboard

Retrier called even with 0 retry count

Open sunjayaali opened this issue 4 years ago • 1 comments

  server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(500)
	}))
	defer server.Close()

	retryCalled := 0
	httpclient := httpclient.NewClient(
		httpclient.WithRetrier(heimdall.NewRetrierFunc(func(_ int) time.Duration {
			retryCalled++
			return 1 * time.Second
		})),
		httpclient.WithRetryCount(0),
	)
	req, err := http.NewRequest(http.MethodGet, server.URL, nil)
	assert.NoError(t, err)
	res, err := httpclient.Do(req)
	assert.NoError(t, err)
	_ = res
	assert.Equal(t, 0, retryCalled)

retrier still called with 0 retry count, is this expected?

sunjayaali avatar Aug 12 '20 07:08 sunjayaali

Another problem that is linked is that time.Sleep(backoffTime) will be called even when the retries are exhausted, which can lead to quite a waste of time for the caller.

If we agree on both these issues, I'd be happy to propose a fix.

vthiery avatar Aug 18 '20 22:08 vthiery