File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212from ducktape .mark .resource import cluster
1313from ducktape .tests .test import Test
1414
15- from rptest .util import check_consistently , expect_exception
15+ from rptest .util import ConditionNotHeldError , check_consistently , expect_exception
1616
1717
1818class CheckConsistentlyTest (Test ):
@@ -56,7 +56,7 @@ def false_from_start() -> bool:
5656 calls += 1
5757 return False
5858
59- with expect_exception (AssertionError , lambda _ : True ):
59+ with expect_exception (ConditionNotHeldError , lambda _ : True ):
6060 check_consistently (false_from_start , duration_sec = 5 , interval_sec = 0.01 )
6161 assert calls == 1
6262
@@ -68,6 +68,11 @@ def flips() -> bool:
6868 calls += 1
6969 return calls < 3
7070
71- with expect_exception (AssertionError , lambda _ : True ):
71+ with expect_exception (ConditionNotHeldError , lambda _ : True ):
7272 check_consistently (flips , duration_sec = 5 , interval_sec = 0.001 )
7373 assert calls == 3
74+
75+ @cluster (num_nodes = 0 )
76+ def test_check_failure_is_still_an_assertion_error (self ) -> None :
77+ with expect_exception (AssertionError , lambda _ : True ):
78+ check_consistently (lambda : False , duration_sec = 5 , interval_sec = 0.01 )
Original file line number Diff line number Diff line change @@ -218,6 +218,12 @@ def wait_until_with_progress_check(
218218 ) from last_exception
219219
220220
221+ class ConditionNotHeldError (AssertionError ):
222+ """Raised when `check_consistently` observes the checked condition returning false."""
223+
224+ pass
225+
226+
221227def check_consistently (
222228 condition : Callable [[], bool ],
223229 duration_sec : float ,
@@ -232,7 +238,7 @@ def check_consistently(
232238 asserts that something good eventually happens (it blocks until a
233239 condition becomes true), whereas `check_consistently` asserts that nothing
234240 bad happens (it blocks while the condition *remains* true, raising
235- AssertionError the moment it returns false).
241+ `ConditionNotHeldError` the moment it returns false).
236242
237243 `condition` is polled every `interval_sec`; the `duration_sec` window is
238244 measured from after the first poll, so at least `duration_sec` elapses
@@ -258,7 +264,9 @@ def check_consistently(
258264 def poll () -> None :
259265 if not condition ():
260266 msg = err_msg () if callable (err_msg ) else err_msg
261- raise AssertionError (msg or f"condition did not hold for { duration_sec } s" )
267+ raise ConditionNotHeldError (
268+ msg or f"condition did not hold for { duration_sec } s"
269+ )
262270
263271 poll ()
264272 stop = time .monotonic () + duration_sec
You can’t perform that action at this time.
0 commit comments