diff --git a/orbit/changes/log-time-format b/orbit/changes/log-time-format new file mode 100644 index 0000000000..00fed61b88 --- /dev/null +++ b/orbit/changes/log-time-format @@ -0,0 +1 @@ +* Fixed a log timestamp to print the right duration value when a fleet update has exceeded the maximum number of retries. diff --git a/pkg/retry/limited_with_cooldown.go b/pkg/retry/limited_with_cooldown.go index fc0c55015b..350b1e50fe 100644 --- a/pkg/retry/limited_with_cooldown.go +++ b/pkg/retry/limited_with_cooldown.go @@ -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 { diff --git a/pkg/retry/limited_with_cooldown_test.go b/pkg/retry/limited_with_cooldown_test.go index 48dbb6f608..d6887d358e 100644 --- a/pkg/retry/limited_with_cooldown_test.go +++ b/pkg/retry/limited_with_cooldown_test.go @@ -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) {