2016-04-05 22:04:37 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2018-03-03 14:53:52 +03:00
|
|
|
"context"
|
2016-04-05 22:04:37 +03:00
|
|
|
"math"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBackoff(t *testing.T) {
|
|
|
|
delta := time.Duration(0)
|
|
|
|
|
|
|
|
for i := 0; i < 5; i++ {
|
2018-04-14 20:06:52 +03:00
|
|
|
d, err := exponentialBackoff(context.TODO(), NewRequest("test", "test", nil), i)
|
2016-04-05 22:04:37 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if d < delta {
|
|
|
|
t.Fatalf("Expected greater than %v, got %v", delta, d)
|
|
|
|
}
|
|
|
|
|
|
|
|
delta = time.Millisecond * time.Duration(math.Pow(10, float64(i+1)))
|
|
|
|
}
|
|
|
|
}
|