Skip to content

Commit ea1609c

Browse files
committed
rptests/util/repeat_check: add a flag for returned value stability
`repeat_check` decorator can be used in `wait_until`/`wait_until_result` to check if the predicate passed for a set number of times in a line. Add a flag for checking the tuple-returning predicate not only passes for the requested number of times, but also returns the same value.
1 parent 83889e1 commit ea1609c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/rptest/util.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,38 @@ def release(self) -> bool:
6565
return self._scale == Scale.RELEASE
6666

6767

68-
def repeat_check(times: int):
68+
def repeat_check(times: int, require_same: bool = False):
6969
def decorator(func):
7070
"""
7171
Decorator to repeat a check function until it passes for a given number
7272
of times in a line. The function should accept no arguments and return
7373
either a tuple where the first element is a boolean
7474
(for wait_until_result), or just a boolean (for plain wait_until).
75+
76+
`require_same` controls whether we require the successful result to be the same
7577
"""
7678

7779
def wrapper():
7880
ret = func()
7981
is_successful = ret[0] if isinstance(ret, tuple) else ret
8082
if is_successful:
83+
if require_same and wrapper._last_successful_result != ret:
84+
wrapper._last_successful_result = ret
85+
wrapper._passed = 0
8186
wrapper._passed += 1
8287
if wrapper._passed >= times:
83-
wrapper._passed = 0 # in case we reuse the function
88+
reinit(wrapper) # in case we reuse the function
8489
return ret
8590
return False, None if isinstance(ret, tuple) else False
8691
else:
87-
wrapper._passed = 0
92+
reinit(wrapper) # reset on failure
8893
return ret
8994

90-
# init the counter
91-
wrapper._passed = 0
95+
def reinit(wrapper):
96+
wrapper._passed = 0
97+
wrapper._last_successful_result = None
98+
99+
reinit(wrapper)
92100

93101
return wrapper
94102

0 commit comments

Comments
 (0)