2from collections.abc
import Callable
6MAX_WAIT_TIME = datetime.timedelta(seconds=30)
7ITERATION_PERIOD_SECONDS = 0.5
16 Waits for some external event for MAX_WAIT_TIME and
17 calls func every ITERATION_PERIOD_SECONDS.
18 If func raises NotReady exception, the waiting continues.
19 If func succesfully returns, wait_until() returns the same value.
20 After MAX_WAIT_TIME of unsuccesfull checks wait_until()
25 .. code-block:: python
27 async def try_to_connect_db():
28 if not db_conn_is_ok():
31 await wait_until(try_to_connect_db)
33 @throws TimeoutError after MAX_WAIT_TIME of unsuccesfull checks
34 @note If possible, use @ref testpoint instead. @ref testpoint is
35 an explicit message from the server "I'm ready", while wait_until()
36 uses an implicit idea "A condition is met, so I can continue".
38 @ingroup userver_testsuite
40 start = datetime.datetime.now()
41 while datetime.datetime.now() - start < MAX_WAIT_TIME:
45 await asyncio.sleep(ITERATION_PERIOD_SECONDS)