Merge pull request #1148 from tpam28/master

fix test and description
This commit is contained in:
Asim Aslam 2020-01-30 17:09:41 +00:00 committed by GitHub
commit 5f6271b044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -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
}

View File

@ -2,13 +2,19 @@ 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 +24,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)))
}
}