@@ -394,6 +394,34 @@ async def test_run(monkeypatch, clear_queue, clear_database):
394394 )
395395
396396
397+ async def test_run_no_sleep (mocker , monkeypatch ):
398+ """'run' should not sleep if the controller completes the loop and another one is already
399+ triggered"""
400+ monkeypatch .setattr (configs , "load_sample_monitors" , True )
401+ monkeypatch .setattr (configs , "internal_monitors_path" , "tests/sample_monitors/internal" )
402+ monkeypatch .setattr (configs , "sample_monitors_path" , "tests/sample_monitors/others" )
403+
404+ run_procedures_mock = AsyncMock ()
405+ monkeypatch .setattr (controller , "run_procedures" , run_procedures_mock )
406+
407+ monkeypatch .setattr (controller , "is_triggered" , lambda * args , ** kwargs : True )
408+
409+ sleep_spy : AsyncMock = mocker .spy (app , "sleep" )
410+
411+ # Run the controller for a while then stop it
412+ await monitors_loader ._register_monitors ()
413+ await monitors_loader ._load_monitors (None )
414+
415+ controller_task = asyncio .create_task (controller .run ())
416+ await asyncio .sleep (0.5 )
417+
418+ # Stop the app and wait for the controller task
419+ app .stop ()
420+ await asyncio .wait_for (controller_task , timeout = 0.5 )
421+
422+ sleep_spy .assert_not_called ()
423+
424+
397425async def test_run_current_task_error (caplog , monkeypatch ):
398426 """'run' should log an error if it can't get the current task and finish the execution"""
399427 monkeypatch .setattr (asyncio , "current_task" , lambda : None )
0 commit comments