diff --git a/e2e/common/retry.go b/e2e/common/retry.go index 9c8aee5d..050d6071 100644 --- a/e2e/common/retry.go +++ b/e2e/common/retry.go @@ -8,11 +8,14 @@ func Retry(attempts int, interval time.Duration, fn func() error) error { ticker := time.NewTicker(interval) defer ticker.Stop() var err error - for range ticker.C { - attempts-- - err = fn() - if err == nil || attempts == 0 { - return err + for attempts > 0 { + select { + case <-ticker.C: + attempts-- + err = fn() + if err == nil { + return err + } } } // Return nil if all attempts fail. @@ -24,11 +27,15 @@ func RetryGet[T any](attempts int, interval time.Duration, fn func() (*T, error) defer ticker.Stop() var err error var obj *T - for range ticker.C { - attempts-- - obj, err = fn() - if err == nil || attempts == 0 { - return obj, err + for + for attempts > 0 { + select { + case <-ticker.C: + attempts-- + obj, err = fn() + if err == nil { + return obj, err + } } } // Return nil object if all attempts fail.