refactor(temp): read the free space where the failed step deletes its temp files

This commit is contained in:
imSp4rky
2026-11-29 15:23:03 -07:00
parent 977cbe4aa8
commit 1ebc3e3624
13 changed files with 155 additions and 59 deletions
+29
View File
@@ -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()