Fix channel worker stalling when stopping ffmpeg with unread stdout
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
from restreamer.ffmpeg_runner import build_ffmpeg_args
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from restreamer import ffmpeg_runner
|
||||
from restreamer.constants import FFMPEG_TERMINATE_TIMEOUT_SECONDS
|
||||
from restreamer.ffmpeg_runner import FfmpegStreamProcess, build_ffmpeg_args
|
||||
from restreamer.resolver import ResolvedStream
|
||||
|
||||
|
||||
@@ -42,3 +48,15 @@ def test_build_ffmpeg_args_maps_separate_video_and_audio_inputs() -> None:
|
||||
assert "-map" in args
|
||||
map_values = [args[i + 1] for i, a in enumerate(args) if a == "-map"]
|
||||
assert map_values == ["0:v:0", "1:a:0"]
|
||||
|
||||
|
||||
async def test_stop_returns_when_consumer_left_stdout_unread(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(ffmpeg_runner, "build_ffmpeg_args", lambda stream: ["yes"])
|
||||
process = FfmpegStreamProcess(ResolvedStream(video_url="https://example.com/stream.m3u8"), "test")
|
||||
await process.start()
|
||||
async for _chunk in process.iter_chunks():
|
||||
break
|
||||
|
||||
await asyncio.wait_for(process.stop(), timeout=FFMPEG_TERMINATE_TIMEOUT_SECONDS / 2)
|
||||
|
||||
assert await process.wait() != 0
|
||||
|
||||
Reference in New Issue
Block a user