@@ -25,6 +25,9 @@ def _make_transparent_png_bytes() -> bytes:
2525TEST_SENTINEL_WAIT_SECONDS = 0.05
2626ERROR_NO_FILE_SENT = "Nenhum arquivo enviado"
2727ERROR_INVALID_MODE = "Modo inválido"
28+ MINIMAL_MP4_BYTES = (
29+ b"\x00 \x00 \x00 \x18 ftypisom\x00 \x00 \x02 \x00 isomiso2"
30+ )
2831
2932
3033def test_process_without_files_returns_400 (client ):
@@ -204,7 +207,7 @@ def test_image_upload_file_count_limit_returns_413(client, monkeypatch):
204207
205208def test_video_upload_file_count_limit_returns_413 (client , monkeypatch ):
206209 monkeypatch .setattr ("app.main.MAX_VIDEO_UPLOAD_FILES" , 1 )
207- fake_video = b"not-a-real-video"
210+ fake_video = MINIMAL_MP4_BYTES
208211 response = client .post (
209212 "/process-video" ,
210213 data = {
@@ -420,17 +423,25 @@ async def fake_process_video(file_path, output_dir, *args, **kwargs):
420423 },
421424 )
422425
426+ old_in_progress = set (main_module .SENTINEL_IN_PROGRESS )
427+ old_recently_handled = dict (main_module .SENTINEL_RECENTLY_HANDLED )
423428 main_module .SENTINEL_IN_PROGRESS .clear ()
424429 main_module .SENTINEL_RECENTLY_HANDLED .clear ()
425430
426- async def _run_once ():
427- task = asyncio .create_task (main_module .sentinel_loop ())
428- await original_sleep (TEST_SENTINEL_WAIT_SECONDS )
429- task .cancel ()
430- with suppress (asyncio .CancelledError ):
431- await task
432-
433- asyncio .run (_run_once ())
431+ try :
432+ async def _run_once ():
433+ task = asyncio .create_task (main_module .sentinel_loop ())
434+ await original_sleep (TEST_SENTINEL_WAIT_SECONDS )
435+ task .cancel ()
436+ with suppress (asyncio .CancelledError ):
437+ await asyncio .gather (task )
438+
439+ asyncio .run (_run_once ())
440+ finally :
441+ main_module .SENTINEL_IN_PROGRESS .clear ()
442+ main_module .SENTINEL_RECENTLY_HANDLED .clear ()
443+ main_module .SENTINEL_IN_PROGRESS .update (old_in_progress )
444+ main_module .SENTINEL_RECENTLY_HANDLED .update (old_recently_handled )
434445
435446 message_types = [msg .get ("type" ) for msg in sent_messages ]
436447 assert "sentinel_start" in message_types
0 commit comments