mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 12:35:13 +00:00
feat(tracks): resume segment decryption and rolling merge through the segment store
This commit is contained in:
@@ -16,7 +16,7 @@ from filelock import FileLock
|
||||
|
||||
from unshackle.commands.env import clear_directory
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.temp import LOCK_NAME, TASK_PREFIX, is_stale, sweep_task_dirs, task_temp_dir
|
||||
from unshackle.core.temp import LOCK_NAME, TASK_PREFIX, claim, is_stale, lock_free, sweep_task_dirs, task_temp_dir
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
@@ -169,6 +169,38 @@ def test_clear_directory_removes_stale_task_dir(temp_root: Path) -> None:
|
||||
files_count, freed_bytes = clear_directory(temp_root)
|
||||
assert not task_dir.exists()
|
||||
assert temp_root.is_dir()
|
||||
# glob("**/*") never matches dotfiles, so .lock is not counted
|
||||
assert files_count == 1
|
||||
assert files_count == 2 # the orphan and the lock file, which the stale probe keeps
|
||||
assert freed_bytes == 5
|
||||
|
||||
|
||||
def test_the_probe_of_a_live_lock_keeps_the_lock_file(temp_root: Path) -> None:
|
||||
task_dir = make_task_dir(temp_root, lock=False)
|
||||
with FileLock(task_dir / LOCK_NAME):
|
||||
assert not lock_free(task_dir)
|
||||
assert (task_dir / LOCK_NAME).exists()
|
||||
task_dir.mkdir(exist_ok=True)
|
||||
(task_dir / LOCK_NAME).touch()
|
||||
assert lock_free(task_dir)
|
||||
assert (task_dir / LOCK_NAME).exists()
|
||||
|
||||
|
||||
@pytest.mark.skipif(os.name == "nt", reason="patches the POSIX lock call")
|
||||
def test_a_lock_call_that_fails_counts_as_held(temp_root: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
import errno
|
||||
import fcntl
|
||||
|
||||
def no_lock(fd: int, operation: int) -> None:
|
||||
raise OSError(errno.ENOSYS, "no lock call")
|
||||
|
||||
monkeypatch.setattr(fcntl, "flock", no_lock)
|
||||
task_dir = make_task_dir(temp_root)
|
||||
backdate(task_dir)
|
||||
sweep_task_dirs(temp_root)
|
||||
assert (task_dir / LOCK_NAME).exists()
|
||||
|
||||
|
||||
def test_a_claimed_task_dir_is_held_for_a_second_sweep(temp_root: Path) -> None:
|
||||
task_dir = make_task_dir(temp_root)
|
||||
with claim(task_dir) as first, claim(task_dir) as second:
|
||||
assert (first, second) == (True, False)
|
||||
assert not lock_free(task_dir)
|
||||
|
||||
Reference in New Issue
Block a user