1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/client/backoff_test.go

32 lines
538 B
Go
Raw Normal View History

2016-04-05 21:04:37 +02:00
package client
import (
2018-03-03 13:53:52 +02:00
"context"
2016-04-05 21:04:37 +02:00
"testing"
"time"
)
func TestBackoff(t *testing.T) {
2020-01-30 19:08:03 +02: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 21:04:37 +02:00
2018-04-14 19:15:09 +02:00
c := NewClient()
2016-04-05 21:04:37 +02:00
for i := 0; i < 5; i++ {
2018-04-14 19:15:09 +02:00
d, err := exponentialBackoff(context.TODO(), c.NewRequest("test", "test", nil), i)
2016-04-05 21:04:37 +02:00
if err != nil {
t.Fatal(err)
}
2020-01-30 18:43:03 +02:00
if d != results[i] {
t.Fatalf("Expected equal than %v, got %v", results[i], d)
2016-04-05 21:04:37 +02:00
}
}
}