gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/client/backoff_test.go (about) 1 package client 2 3 import ( 4 "context" 5 "math" 6 "testing" 7 "time" 8 ) 9 10 func TestBackoff(t *testing.T) { 11 delta := time.Duration(0) 12 13 c := NewClient() 14 15 for i := 0; i < 5; i++ { 16 d, err := exponentialBackoff(context.TODO(), c.NewRequest("test", "test", nil), i) 17 if err != nil { 18 t.Fatal(err) 19 } 20 21 if d < delta { 22 t.Fatalf("Expected greater than %v, got %v", delta, d) 23 } 24 25 delta = time.Millisecond * time.Duration(math.Pow(10, float64(i+1))) 26 } 27 }