forked from kenzuya/unshackle
refactor(temp): read the free space where the failed step deletes its temp files
This commit is contained in:
@@ -21,7 +21,7 @@ import unshackle.commands.dl as dl_module
|
||||
from tests.admission import refusal
|
||||
from tests.remote.sessions import launch_session
|
||||
from tests.remote.unit.test_remote_service_helpers import _sent_create_data
|
||||
from unshackle.core import mux_step
|
||||
from unshackle.core import mux_step, temp
|
||||
from unshackle.core.api import download_manager, handlers, key_policy
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.mux_step import hybrid_plan, hybrid_source_tracks, hybrid_step_error, missing_hybrid_error
|
||||
@@ -705,10 +705,38 @@ def test_a_hybrid_failure_is_reported_so_the_title_goes_on(monkeypatch: pytest.M
|
||||
raise error
|
||||
|
||||
monkeypatch.setattr(mux_step, "Hybrid", failed_hybrid)
|
||||
monkeypatch.setattr(temp, "LOW_FREE_SPACE", 0)
|
||||
|
||||
assert hybrid_step_error([], "TEST", "HDR10-DV-2160p.hevc") == str(error)
|
||||
|
||||
|
||||
def test_a_hybrid_that_fills_the_temp_volume_names_the_free_space_before_its_files_go(
|
||||
quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
base = tmp_path / "base.mkv"
|
||||
base.write_bytes(b"")
|
||||
stream = tmp_path / "HDR10.hevc"
|
||||
present: list[bool] = []
|
||||
|
||||
def full(self: Hybrid) -> None:
|
||||
stream.write_bytes(b"hevc")
|
||||
raise OSError(28, "No space left on device")
|
||||
|
||||
def usage(path: Any) -> Any:
|
||||
present.append(stream.exists())
|
||||
return SimpleNamespace(free=38_000_000)
|
||||
|
||||
stub_hybrid_steps(monkeypatch, "measure_dv", "level_6")
|
||||
monkeypatch.setattr(Hybrid, "injecting", full)
|
||||
monkeypatch.setattr(temp.shutil, "disk_usage", usage)
|
||||
video = SimpleNamespace(id="b", path=base, width=None, height=2160, range=Video.Range.HDR10)
|
||||
|
||||
error = hybrid_step_error([video], "TEST", "HDR10-DV-2160p.hevc") # type: ignore[list-item]
|
||||
|
||||
assert error == f"[Errno 28] No space left on device, 38.0 MB free on {tmp_path}"
|
||||
assert present == [True] and not stream.exists()
|
||||
|
||||
|
||||
def test_a_working_hybrid_reports_no_error_and_an_exit_passes_through(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
seen: dict[str, Any] = {}
|
||||
monkeypatch.setattr(mux_step, "Hybrid", lambda tracks, source, output_name: seen.update(name=output_name))
|
||||
|
||||
@@ -17,8 +17,8 @@ import pytest
|
||||
from pywidevine.pssh import PSSH
|
||||
|
||||
from tests.core.key_resolver import key_table, resolver, vaults_of
|
||||
from unshackle.commands import dl as dl_module
|
||||
from unshackle.commands.dl import dl
|
||||
from unshackle.core import temp
|
||||
from unshackle.core.drm import Widevine, key_resolution
|
||||
from unshackle.core.drm.key_resolution import ContentKeyResolver
|
||||
from unshackle.core.import_service import ImportService
|
||||
@@ -119,7 +119,7 @@ def test_the_retry_after_a_bad_vault_key_ends_in_the_import_error(
|
||||
|
||||
|
||||
def test_a_download_stopped_by_a_click_exception_reports_only_its_message(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(dl_module, "LOW_FREE_SPACE", 0)
|
||||
monkeypatch.setattr(temp, "LOW_FREE_SPACE", 0)
|
||||
error = ImportService.missing_key(SimpleNamespace(drm=[FakeDRM({})]))
|
||||
|
||||
lines = dl.failure_lines(error)
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core import binaries
|
||||
from unshackle.core import temp as temp_module
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.mux_step import mux_title
|
||||
from unshackle.core.placement import Placement
|
||||
@@ -17,6 +20,11 @@ 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")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def roomy_temp(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(temp_module, "LOW_FREE_SPACE", 0)
|
||||
|
||||
|
||||
def mux(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, script: str) -> None:
|
||||
monkeypatch.setattr(config.directories, "temp", tmp_path)
|
||||
stub = tmp_path / "mkvmerge"
|
||||
@@ -70,3 +78,24 @@ def test_a_killed_muxer_stops_the_run(tmp_path: Path, monkeypatch: pytest.Monkey
|
||||
mux(tmp_path, monkeypatch, "kill -9 $$")
|
||||
|
||||
assert raised.value.reason == "mkvmerge failed (signal 9)"
|
||||
|
||||
|
||||
def test_the_stop_names_a_nearly_full_temp_volume_read_before_the_temp_files_go(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
rpu = tmp_path / "RPU.bin"
|
||||
rpu.write_bytes(b"rpu")
|
||||
seen: list[bool] = []
|
||||
|
||||
def usage(path: Any) -> Any:
|
||||
seen.append(rpu.exists())
|
||||
return SimpleNamespace(free=38_000_000)
|
||||
|
||||
monkeypatch.setattr(temp_module, "LOW_FREE_SPACE", 1024**3)
|
||||
monkeypatch.setattr(temp_module.shutil, "disk_usage", usage)
|
||||
with pytest.raises(RunStopped) as raised:
|
||||
mux(tmp_path, monkeypatch, "exit 2")
|
||||
|
||||
assert raised.value.reason == f"mkvmerge failed (exit 2), 38.0 MB free on {tmp_path}"
|
||||
assert seen == [True]
|
||||
assert not rpu.exists()
|
||||
|
||||
@@ -13,6 +13,7 @@ from uuid import UUID
|
||||
import pytest
|
||||
|
||||
from tests.core.test_all_drm import playready, widevine
|
||||
from unshackle.core import temp
|
||||
from unshackle.core.constants import DOWNLOAD_CANCELLED
|
||||
from unshackle.core.drm import ClearKey, ClearKeyCENC, ClearKeyCTR, MonaLisa, verify
|
||||
from unshackle.core.events import events
|
||||
@@ -192,6 +193,22 @@ def test_a_failure_closes_the_decrypter_and_removes_the_output(tmp_path, seen):
|
||||
assert not ctx.save_path.exists()
|
||||
|
||||
|
||||
def test_a_failed_rolling_merge_reads_the_free_space_before_it_removes_the_output(tmp_path, monkeypatch):
|
||||
ctx = make_ctx(tmp_path)
|
||||
present: list[bool] = []
|
||||
|
||||
def usage(path: Any) -> Any:
|
||||
present.append(ctx.save_path.exists())
|
||||
return SimpleNamespace(free=38_000_000)
|
||||
|
||||
monkeypatch.setattr(temp.shutil, "disk_usage", usage)
|
||||
with pytest.raises(ConnectionError) as raised:
|
||||
fetch(ctx, FakeDownloader(fail_after=2), rolling=True, init=INIT)
|
||||
|
||||
assert present == [True] and not ctx.save_path.exists()
|
||||
assert temp.low_free_space(raised.value).startswith(", 38.0 MB free on ")
|
||||
|
||||
|
||||
def test_a_short_rolling_merge_raises_and_removes_the_output(tmp_path):
|
||||
ctx = make_ctx(tmp_path)
|
||||
ctx.save_path.write_bytes(INIT)
|
||||
|
||||
Reference in New Issue
Block a user