micro/client/backoff_test.go

35 lines
549 B
Go
Raw Normal View History

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
"testing"
"time"
)
func TestBackoff(t *testing.T) {
2020-01-30 20:08:03 +03:00
results := []time.Duration{
0 * time.Second,
100 * time.Millisecond,
600 * time.Millisecond,
1900 * time.Millisecond,
4300 * time.Millisecond,
7900 * time.Millisecond,
}
2016-04-05 22:04:37 +03:00
r := &testRequest{
service: "test",
method: "test",
}
2018-04-14 20:15:09 +03:00
2016-04-05 22:04:37 +03:00
for i := 0; i < 5; i++ {
d, err := exponentialBackoff(context.TODO(), r, i)
2016-04-05 22:04:37 +03:00
if err != nil {
t.Fatal(err)
}
2020-01-30 19:43:03 +03:00
if d != results[i] {
t.Fatalf("Expected equal than %v, got %v", results[i], d)
2016-04-05 22:04:37 +03:00
}
}
}