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