Skip to content

Commit 563e874

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 8d974f9 commit 563e874

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
@@ -187,11 +187,19 @@ def callable_marker(value: T | Callable[..., T], request: pytest.FixtureRequest)
187187
else:
188188
return value
189189

190-
def wait_for(fn: Callable[[], object], msg: str | None = None, timeout_secs: int = 2 * 60, retry_delay_secs: int = 2,
191-
invert: bool = False) -> None:
190+
def wait_for(
191+
fn: Callable[[], object],
192+
msg: str | None = None,
193+
timeout_secs: int = 2 * 60,
194+
retry_delay_secs: int = 2,
195+
delayed_start_secs: int = 0,
196+
invert: bool = False,
197+
) -> None:
192198
if msg is not None:
193199
logging.info(msg)
194200
start_time = time.perf_counter()
201+
if delayed_start_secs:
202+
time.sleep(delayed_start_secs)
195203
while True:
196204
ret = fn()
197205
if not invert and ret:
@@ -206,9 +214,13 @@ def wait_for(fn: Callable[[], object], msg: str | None = None, timeout_secs: int
206214
time.sleep(retry_delay_secs)
207215

208216
def wait_for_not(
209-
fn: Callable[[], Any], msg: str | None = None, timeout_secs: int = 2 * 60, retry_delay_secs: int = 2
217+
fn: Callable[[], Any],
218+
msg: str | None = None,
219+
timeout_secs: int = 2 * 60,
220+
retry_delay_secs: int = 2,
221+
delayed_start_secs: int = 0,
210222
) -> None:
211-
return wait_for(fn, msg, timeout_secs, retry_delay_secs, True)
223+
return wait_for(fn, msg, timeout_secs, retry_delay_secs, delayed_start_secs, True)
212224

213225
def is_uuid(maybe_uuid: str) -> bool:
214226
try:

0 commit comments

Comments
 (0)