Skip to content

Commit b7d3cfe

Browse files
committed
wait_for/wait_for_not: introduce delayed_start_secs
add a programable delayed start before testing fn() default to 0 (no delay). Signed-off-by: Sebastien Rodot <sebastien.rodot@vates.tech>
1 parent 80e23a7 commit b7d3cfe

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

lib/common.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,19 @@ def callable_marker(value: T | Callable[..., T], request: pytest.FixtureRequest)
192192
else:
193193
return value
194194

195-
def wait_for(fn: Callable[[], object], msg: str | None = None, timeout_secs: int = 2 * 60, retry_delay_secs: int = 2,
196-
invert: bool = False) -> None:
195+
def wait_for(
196+
fn: Callable[[], object],
197+
msg: str | None = None,
198+
timeout_secs: int = 2 * 60,
199+
retry_delay_secs: int = 2,
200+
delayed_start_secs: int = 0,
201+
invert: bool = False,
202+
) -> None:
197203
if msg is not None:
198204
logging.info(msg)
199205
start_time = time.perf_counter()
206+
if delayed_start_secs:
207+
time.sleep(delayed_start_secs)
200208
while True:
201209
ret = fn()
202210
if not invert and ret:
@@ -211,9 +219,13 @@ def wait_for(fn: Callable[[], object], msg: str | None = None, timeout_secs: int
211219
time.sleep(retry_delay_secs)
212220

213221
def wait_for_not(
214-
fn: Callable[[], Any], msg: str | None = None, timeout_secs: int = 2 * 60, retry_delay_secs: int = 2
222+
fn: Callable[[], Any],
223+
msg: str | None = None,
224+
timeout_secs: int = 2 * 60,
225+
retry_delay_secs: int = 2,
226+
delayed_start_secs: int = 0,
215227
) -> None:
216-
return wait_for(fn, msg, timeout_secs, retry_delay_secs, True)
228+
return wait_for(fn, msg, timeout_secs, retry_delay_secs, delayed_start_secs, True)
217229

218230
def is_uuid(maybe_uuid: str) -> bool:
219231
try:

0 commit comments

Comments
 (0)