One more test case for retry

pull/55/head
V2Ray 9 years ago
parent f080f36372
commit d58384ced0

@ -16,11 +16,12 @@ func TestNoRetry(t *testing.T) {
assert := unit.Assert(t)
startTime := time.Now().Unix()
Timed(10, 100000).On(func() error {
err := Timed(10, 100000).On(func() error {
return nil
})
endTime := time.Now().Unix()
assert.Error(err).IsNil()
assert.Int64(endTime - startTime).AtLeast(0)
}
@ -29,7 +30,7 @@ func TestRetryOnce(t *testing.T) {
startTime := time.Now()
called := 0
Timed(10, 1000).On(func() error {
err := Timed(10, 1000).On(func() error {
if called == 0 {
called++
return TestError
@ -38,6 +39,7 @@ func TestRetryOnce(t *testing.T) {
})
duration := time.Since(startTime)
assert.Error(err).IsNil()
assert.Int64(int64(duration / time.Millisecond)).AtLeast(900)
}
@ -46,7 +48,7 @@ func TestRetryMultiple(t *testing.T) {
startTime := time.Now()
called := 0
Timed(10, 1000).On(func() error {
err := Timed(10, 1000).On(func() error {
if called < 5 {
called++
return TestError
@ -55,5 +57,24 @@ func TestRetryMultiple(t *testing.T) {
})
duration := time.Since(startTime)
assert.Error(err).IsNil()
assert.Int64(int64(duration / time.Millisecond)).AtLeast(4900)
}
func TestRetryExhausted(t *testing.T) {
assert := unit.Assert(t)
startTime := time.Now()
called := 0
err := Timed(2, 1000).On(func() error {
if called < 5 {
called++
return TestError
}
return nil
})
duration := time.Since(startTime)
assert.Error(err).Equals(RetryFailed)
assert.Int64(int64(duration / time.Millisecond)).AtLeast(1900)
}

Loading…
Cancel
Save