1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-03 15:55:20 -05:00

add exponential backoff as retry logic

This commit is contained in:
Darien Raymond
2016-11-20 21:47:51 +01:00
parent 56fb8c478c
commit 30cd9e929d
7 changed files with 58 additions and 27 deletions

View File

@@ -68,14 +68,26 @@ func TestRetryExhausted(t *testing.T) {
startTime := time.Now()
called := 0
err := Timed(2, 1000).On(func() error {
if called < 5 {
called++
return errorTestOnly
}
return nil
called++
return errorTestOnly
})
duration := time.Since(startTime)
assert.Error(err).Equals(ErrRetryFailed)
assert.Int64(int64(duration / time.Millisecond)).AtLeast(1900)
}
func TestExponentialBackoff(t *testing.T) {
assert := assert.On(t)
startTime := time.Now()
called := 0
err := ExponentialBackoff(10, 100).On(func() error {
called++
return errorTestOnly
})
duration := time.Since(startTime)
assert.Error(err).Equals(ErrRetryFailed)
assert.Int64(int64(duration / time.Millisecond)).AtLeast(4000)
}