From 7f1968cfbd039af68c899aafe32862633902b251 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Wed, 7 Aug 2024 00:42:32 +0200 Subject: [PATCH] contextutil: sleep between tries in safe_while again This patch fixes an issue introduced within PR #1816, that when tries are < 0 (e.g. -1) there is no sleep occurred between tries. It also fixes error message, so we repot correct number of tries we've done now. Fixes: ee43f87cfe88a8155566b662750d663c1d8742ff Signed-off-by: Kyr Shatskyy --- teuthology/contextutil.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/teuthology/contextutil.py b/teuthology/contextutil.py index dd6d2d68a7..8e53e5439b 100644 --- a/teuthology/contextutil.py +++ b/teuthology/contextutil.py @@ -115,20 +115,20 @@ class safe_while(object): msg = msg.format( action=self.action, - tries=self.counter, + tries=self.counter - 1, total=self.total_seconds, ) return msg def __call__(self): - if self.tries < 0: - return True self.counter += 1 if self.counter == 1: return True + def must_stop(): + return self.tries > 0 and self.counter > self.tries if ((self.timeout > 0 and self.total_seconds >= self.timeout) or - (self.timeout == 0 and self.counter > self.tries)): + (self.timeout == 0 and must_stop())): error_msg = self._make_error_msg() if self._raise: raise MaxWhileTries(error_msg) -- 2.39.5