mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
26 lines
431 B
Go
26 lines
431 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBackoff(t *testing.T) {
|
|
delta := time.Duration(0)
|
|
|
|
for i := 0; i < 5; i++ {
|
|
d, err := exponentialBackoff(context.TODO(), NewRequest("test", "test", nil), i)
|
|
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)))
|
|
}
|
|
}
|