From f6fcfcb8fc18d2533328c095025a355b8add8121 Mon Sep 17 00:00:00 2001 From: Evgeniy Date: Thu, 30 Jan 2020 17:25:07 +0300 Subject: [PATCH] exponentialBackoff was changed from power function to exponential function --- client/backoff.go | 7 ++----- client/backoff_test.go | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/client/backoff.go b/client/backoff.go index 57407a06..4a7e3746 100644 --- a/client/backoff.go +++ b/client/backoff.go @@ -8,10 +8,7 @@ import ( type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) -// exponential backoff +// exponential backoff multiplied by a factor of 0.1 second. func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) { - if attempts == 0 { - return time.Duration(0), nil - } - return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond, nil + return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100, nil } diff --git a/client/backoff_test.go b/client/backoff_test.go index 60ae19aa..a6d39dee 100644 --- a/client/backoff_test.go +++ b/client/backoff_test.go @@ -22,6 +22,6 @@ func TestBackoff(t *testing.T) { t.Fatalf("Expected greater than %v, got %v", delta, d) } - delta = time.Millisecond * time.Duration(math.Pow(10, float64(i+1))) + delta = time.Millisecond * 100 * time.Duration(math.Pow(math.E, float64(i))) } }