fix log with next retry time once max retries are exceeded (#16026)
This commit is contained in:
@@ -64,7 +64,7 @@ func (t *LimitedWithCooldown) Do(hash string, fn func() error) error {
|
||||
|
||||
if t.retries[hash] >= t.maxRetries &&
|
||||
time.Since(t.wait[hash]) <= t.cooldown {
|
||||
return &ExcessRetriesError{nextRetry: time.Until(t.wait[hash])}
|
||||
return &ExcessRetriesError{nextRetry: time.Until(t.wait[hash].Add(t.cooldown))}
|
||||
}
|
||||
|
||||
if err := fn(); err != nil {
|
||||
|
||||
@@ -51,7 +51,8 @@ func TestLimitedWithCooldwonDo(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("exceed max retries", func(t *testing.T) {
|
||||
lwc := NewLimitedWithCooldown(3, 1*time.Hour)
|
||||
cooldown := 1 * time.Hour
|
||||
lwc := NewLimitedWithCooldown(3, cooldown)
|
||||
hash := "foo"
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
@@ -64,8 +65,9 @@ func TestLimitedWithCooldwonDo(t *testing.T) {
|
||||
err := lwc.Do(hash, func() error {
|
||||
return nil
|
||||
})
|
||||
var rErr *ExcessRetriesError
|
||||
require.ErrorAs(t, err, &rErr)
|
||||
rErr, ok := err.(*ExcessRetriesError)
|
||||
require.True(t, ok)
|
||||
require.WithinDuration(t, time.Now().Add(cooldown), time.Now().Add(rErr.nextRetry), 1*time.Minute)
|
||||
})
|
||||
|
||||
t.Run("cooldown period", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user