1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-14 09:42:28 +08:00

Add Retry backoff policy (#173)

The aim of this policy is to enable the configuration of various types of backoff mathematical curves. Should this modification be deemed suitable,
I will proceed to implement an exponential curve backoff policy and set of custom backoff policy
Warning: It's major break
This commit is contained in:
donutloop
2024-02-21 03:20:24 +01:00
committed by GitHub
parent cd156dba5f
commit cacbf97223
3 changed files with 49 additions and 20 deletions

View File

@@ -20,7 +20,7 @@ func TestRetryFailed(t *testing.T) {
return errors.New("error occurs")
}
err := Retry(increaseNumber, RetryDuration(time.Microsecond*50))
err := Retry(increaseNumber, RetryWithLinearBackoff(time.Microsecond*50))
assert.IsNotNil(err)
assert.Equal(DefaultRetryTimes, number)
@@ -40,7 +40,7 @@ func TestRetrySucceeded(t *testing.T) {
return errors.New("error occurs")
}
err := Retry(increaseNumber, RetryDuration(time.Microsecond*50))
err := Retry(increaseNumber, RetryWithLinearBackoff(time.Microsecond*50))
assert.IsNil(err)
assert.Equal(DefaultRetryTimes, number)
@@ -57,7 +57,7 @@ func TestSetRetryTimes(t *testing.T) {
return errors.New("error occurs")
}
err := Retry(increaseNumber, RetryDuration(time.Microsecond*50), RetryTimes(3))
err := Retry(increaseNumber, RetryWithLinearBackoff(time.Microsecond*50), RetryTimes(3))
assert.IsNotNil(err)
assert.Equal(3, number)
@@ -79,7 +79,7 @@ func TestCancelRetry(t *testing.T) {
}
err := Retry(increaseNumber,
RetryDuration(time.Microsecond*50),
RetryWithLinearBackoff(time.Microsecond*50),
Context(ctx),
)