fix log with next retry time once max retries are exceeded (#16026)

This commit is contained in:
Roberto Dip 2024-01-10 17:53:30 -03:00 committed by GitHub
parent 95b1c0df62
commit 3f302a79b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View file

@ -0,0 +1 @@
* Fixed a log timestamp to print the right duration value when a fleet update has exceeded the maximum number of retries.

View file

@ -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 {

View file

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