From ffb9da0230d3d1df677504466126570c39ef2bec Mon Sep 17 00:00:00 2001 From: Evgeniy Date: Thu, 30 Jan 2020 19:43:03 +0300 Subject: [PATCH] fix test and description --- client/backoff.go | 2 +- client/backoff_test.go | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/client/backoff.go b/client/backoff.go index 4a7e3746..70070da2 100644 --- a/client/backoff.go +++ b/client/backoff.go @@ -8,7 +8,7 @@ import ( type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) -// exponential backoff multiplied by a factor of 0.1 second. +// exponential backoff is a function x^e multiplied by a factor of 0.1 second. func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) { 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 a6d39dee..75963cbf 100644 --- a/client/backoff_test.go +++ b/client/backoff_test.go @@ -2,13 +2,12 @@ package client import ( "context" - "math" "testing" "time" ) func TestBackoff(t *testing.T) { - delta := time.Duration(0) + results := []time.Duration{0 * time.Second, 100 * time.Millisecond, 600 * time.Millisecond, 1900 * time.Millisecond, 4300 * time.Millisecond, 7900 * time.Millisecond} c := NewClient() @@ -18,10 +17,8 @@ func TestBackoff(t *testing.T) { t.Fatal(err) } - if d < delta { - t.Fatalf("Expected greater than %v, got %v", delta, d) + if d != results[i] { + t.Fatalf("Expected equal than %v, got %v", results[i], d) } - - delta = time.Millisecond * 100 * time.Duration(math.Pow(math.E, float64(i))) } }