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 authored and GitHub committed 2024-02-21 10:20:24 +08:00
1 parent cd156dba5f
commit cacbf97223
3 files changed
+49 -20

No files matched your search

+4 -4
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),
)