1010import pytest
1111import pytest_asyncio
1212from servicelib .aiohttp import monitor_slow_callbacks
13- from servicelib .aiohttp .aiopg_utils import DatabaseError
1413from tenacity import retry
1514from tenacity .stop import stop_after_attempt
1615from tenacity .wait import wait_fixed
1716
1817
19- async def slow_task (delay ):
20- time .sleep (delay ) # noqa: ASYNC101
18+ async def _slow_function (delay ):
19+ time .sleep (delay ) # noqa: ASYNC251
2120
2221
2322@retry (wait = wait_fixed (1 ), stop = stop_after_attempt (2 ))
24- async def fails_to_reach_pg_db ():
25- raise DatabaseError
23+ async def _raising_function ():
24+ msg = "This function is expected to raise an error"
25+ raise RuntimeError (msg )
2626
2727
2828@pytest_asyncio .fixture (loop_scope = "function" , scope = "function" )
@@ -31,12 +31,12 @@ async def incidents_manager() -> dict:
3131 monitor_slow_callbacks .enable (slow_duration_secs = 0.2 , incidents = incidents )
3232
3333 event_loop = asyncio .get_running_loop ()
34- asyncio .ensure_future (slow_task (0.3 ), loop = event_loop ) # noqa: RUF006
35- asyncio .ensure_future (slow_task (0.3 ), loop = event_loop ) # noqa: RUF006
36- asyncio .ensure_future (slow_task (0.4 ), loop = event_loop ) # noqa: RUF006
34+ asyncio .ensure_future (_slow_function (0.3 ), loop = event_loop ) # noqa: RUF006
35+ asyncio .ensure_future (_slow_function (0.3 ), loop = event_loop ) # noqa: RUF006
36+ asyncio .ensure_future (_slow_function (0.4 ), loop = event_loop ) # noqa: RUF006
3737
3838 incidents_pg = None # aiopg_utils.monitor_pg_responsiveness.enable()
39- asyncio .ensure_future (fails_to_reach_pg_db (), loop = event_loop ) # noqa: RUF006
39+ asyncio .ensure_future (_raising_function (), loop = event_loop ) # noqa: RUF006
4040
4141 return {"slow_callback" : incidents , "posgres_responsive" : incidents_pg }
4242
@@ -48,6 +48,10 @@ def disable_monitoring() -> Iterable[None]:
4848 asyncio .events .Handle ._run = original_handler # noqa: SLF001
4949
5050
51+ @pytest .mark .skip (
52+ reason = "log_slow_callbacks is not supported out-of-the-box with uvloop."
53+ " SEE https://github.com/ITISFoundation/osparc-simcore/issues/8047"
54+ )
5155async def test_slow_task_incident (disable_monitoring : None , incidents_manager : dict ):
5256 await asyncio .sleep (2 )
5357 assert len (incidents_manager ["slow_callback" ]) == 3
0 commit comments