forked from kenzuya/unshackle
fix(dl): stop a failed mux with one line that names the free space
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
"""A failed mkvmerge stops the run with one line that names the tool, its exit and its error."""
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.mux_step import mux_title
|
||||
from unshackle.core.placement import Placement
|
||||
from unshackle.core.run_plan import RunStopped
|
||||
from unshackle.core.titles import Movie
|
||||
from unshackle.core.tracks import Video
|
||||
from unshackle.core.tracks import tracks as tracks_module
|
||||
|
||||
pytestmark = pytest.mark.skipif(not Path("/bin/sh").exists(), reason="needs a POSIX shell for the mkvmerge stub")
|
||||
|
||||
|
||||
def mux(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, script: str) -> None:
|
||||
monkeypatch.setattr(config.directories, "temp", tmp_path)
|
||||
stub = tmp_path / "mkvmerge"
|
||||
stub.write_text(f"#!/bin/sh\n{script}\n")
|
||||
stub.chmod(0o755)
|
||||
monkeypatch.setattr(binaries, "MKVToolNix", stub)
|
||||
monkeypatch.setattr(tracks_module, "file_track_ids", lambda path: {"video": 0})
|
||||
movie = Movie(id_="movie-0001", service=type("EXAMPLE", (), {}), name="Some Movie", year=2024)
|
||||
video = Video(url="https://x.example/v.m3u8", language="en", codec=Video.Codec.AVC, id_="v")
|
||||
video.path = tmp_path / "v.mp4"
|
||||
video.path.write_bytes(b"video")
|
||||
movie.tracks.add(video)
|
||||
mux_title(
|
||||
movie,
|
||||
Placement(movie, root=tmp_path / "out", no_folder=True, no_source=True, sample=False),
|
||||
log=logging.getLogger("dl"),
|
||||
service_tag="EXAMPLE",
|
||||
split_audio=None,
|
||||
merge_video=None,
|
||||
audio_expected=False,
|
||||
skip_subtitles=True,
|
||||
quality=[],
|
||||
range_=[],
|
||||
vcodec=[],
|
||||
generate_dv=False,
|
||||
progress_sink=None,
|
||||
write_sidecars=None,
|
||||
)
|
||||
|
||||
|
||||
def test_a_write_error_is_the_reason_of_the_stop(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
error = "The drive may be full. Exception details: No space left to write to"
|
||||
with pytest.raises(RunStopped) as raised:
|
||||
mux(tmp_path, monkeypatch, f"echo '#GUI#warning a minor thing'\necho '#GUI#error {error}'\nexit 2")
|
||||
|
||||
assert raised.value.reason == f"mkvmerge failed (exit 2): {error}"
|
||||
assert [r.levelno for r in caplog.records if r.name == "dl" and r.levelno > logging.DEBUG] == [logging.WARNING]
|
||||
|
||||
|
||||
def test_a_failure_with_no_error_line_names_the_exit(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
with pytest.raises(RunStopped) as raised:
|
||||
mux(tmp_path, monkeypatch, "exit 2")
|
||||
|
||||
assert raised.value.reason == "mkvmerge failed (exit 2)"
|
||||
|
||||
|
||||
def test_a_killed_muxer_stops_the_run(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
with pytest.raises(RunStopped) as raised:
|
||||
mux(tmp_path, monkeypatch, "kill -9 $$")
|
||||
|
||||
assert raised.value.reason == "mkvmerge failed (signal 9)"
|
||||
@@ -28,7 +28,10 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
import pytest
|
||||
from requests import Session
|
||||
|
||||
from tests.downloaders.test_outage_budget import _FullDisk
|
||||
from unshackle.core.api.errors import categorize_exception
|
||||
from unshackle.core.constants import DownloadCancelled
|
||||
from unshackle.core.remote_protocol import APIErrorCode
|
||||
from unshackle.core.utils.sslciphers import SSLCiphers
|
||||
|
||||
dl = importlib.import_module("unshackle.core.downloaders.requests")
|
||||
@@ -103,6 +106,11 @@ def die_without_result(queue, kwargs):
|
||||
os._exit(3)
|
||||
|
||||
|
||||
def full_disk_worker(queue, kwargs):
|
||||
dl.open = _FullDisk
|
||||
dl.mp_worker(queue, kwargs)
|
||||
|
||||
|
||||
def run_mp(urls, tmp_path):
|
||||
for _ in dl.download_multiprocess(
|
||||
urls=urls,
|
||||
@@ -148,9 +156,20 @@ def test_multiprocess_child_crash_raises(server, tmp_path):
|
||||
# any retry loop), so the child sends __mp_error__ fast; the sibling downloads normally.
|
||||
good = {"url": url(server, "/seg/0.bin")}
|
||||
bad = {"nourl": True}
|
||||
with pytest.raises(RuntimeError):
|
||||
with pytest.raises(RuntimeError) as raised:
|
||||
run_mp([good, bad], tmp_path)
|
||||
|
||||
assert not hasattr(raised.value, "error_code")
|
||||
|
||||
|
||||
def test_a_full_disk_in_a_child_keeps_its_download_error_code(server, tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(dl, "mp_worker", full_disk_worker)
|
||||
with pytest.raises(RuntimeError) as raised:
|
||||
run_mp([{"url": url(server, "/seg/0.bin")}, {"url": url(server, "/seg/1.bin")}], tmp_path)
|
||||
|
||||
assert dl.retries_exhausted(raised.value)
|
||||
assert categorize_exception(raised.value).error_code == APIErrorCode.DOWNLOAD_ERROR
|
||||
|
||||
|
||||
def test_multiprocess_child_death_raises(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(dl, "mp_worker", die_without_result)
|
||||
|
||||
Reference in New Issue
Block a user