1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00

One more test case for retry

This commit is contained in:
V2Ray 2015-11-03 00:12:25 +01:00
parent f080f36372
commit d58384ced0

View File

@ -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)
}