micro/client/backoff_test.go
Asim Aslam 563768b58a
v3 refactor (#1868)
* Move to v3

Co-authored-by: Ben Toogood <bentoogood@gmail.com>
2020-07-27 13:22:00 +01:00

35 lines
549 B
Go

package client
import (
"context"
"testing"
"time"
)
func TestBackoff(t *testing.T) {
results := []time.Duration{
0 * time.Second,
100 * time.Millisecond,
600 * time.Millisecond,
1900 * time.Millisecond,
4300 * time.Millisecond,
7900 * time.Millisecond,
}
r := &testRequest{
service: "test",
method: "test",
}
for i := 0; i < 5; i++ {
d, err := exponentialBackoff(context.TODO(), r, i)
if err != nil {
t.Fatal(err)
}
if d != results[i] {
t.Fatalf("Expected equal than %v, got %v", results[i], d)
}
}
}