From: Zack Cerza Date: Tue, 28 Feb 2023 00:31:07 +0000 (-0700) Subject: safe_while: Retry forever when tries == -1 X-Git-Tag: 1.2.0~125^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ee43f87cfe88a8155566b662750d663c1d8742ff;p=teuthology.git safe_while: Retry forever when tries == -1 Signed-off-by: Zack Cerza --- diff --git a/teuthology/contextutil.py b/teuthology/contextutil.py index 57a0f08c8..c4d86c9a0 100644 --- a/teuthology/contextutil.py +++ b/teuthology/contextutil.py @@ -124,6 +124,8 @@ class safe_while(object): return msg def __call__(self): + if self.tries < 0: + return True self.counter += 1 if self.counter == 1: return True diff --git a/teuthology/test/test_contextutil.py b/teuthology/test/test_contextutil.py index c433c82c9..85b1d51d2 100644 --- a/teuthology/test/test_contextutil.py +++ b/teuthology/test/test_contextutil.py @@ -66,3 +66,9 @@ class TestSafeWhile(object): pass assert True + + def test_tries(self): + attempts = 0 + with self.s_while(tries=-1, _sleeper=self.fake_sleep) as proceed: + while attempts < 100 and proceed(): + attempts += 1