]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
safe_while: Retry forever when tries == -1
authorZack Cerza <zack@redhat.com>
Tue, 28 Feb 2023 00:31:07 +0000 (17:31 -0700)
committerZack Cerza <zack@redhat.com>
Tue, 28 Feb 2023 00:31:07 +0000 (17:31 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/contextutil.py
teuthology/test/test_contextutil.py

index 57a0f08c86b6dbc969350aca850f188d2ef0f8a2..c4d86c9a0914912f7d83c57a678c4562fd28cf87 100644 (file)
@@ -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
index c433c82c90c4fed83c298e0d9b81b7afda15097d..85b1d51d2753a846e7e40b835912f77024befb22 100644 (file)
@@ -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