Merge pull request #1146 from tpam28/master

exponentialBackoff was changed from power function to exponential
This commit is contained in:
Asim Aslam 2020-01-30 14:35:17 +00:00 committed by GitHub
commit 50ac642666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 6 deletions

View File

@ -8,10 +8,7 @@ import (
type BackoffFunc func(ctx context.Context, req Request, attempts int) (time.Duration, error) 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) { func exponentialBackoff(ctx context.Context, req Request, attempts int) (time.Duration, error) {
if attempts == 0 { return time.Duration(math.Pow(float64(attempts), math.E)) * time.Millisecond * 100, nil
return time.Duration(0), nil
}
return time.Duration(math.Pow(10, float64(attempts))) * time.Millisecond, nil
} }

View File

@ -22,6 +22,6 @@ func TestBackoff(t *testing.T) {
t.Fatalf("Expected greater than %v, got %v", delta, d) 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)))
} }
} }