29 lines
889 B
Python
29 lines
889 B
Python
"""Lock acquisition ordering (deadlock prevention)."""
|
|
|
|
import pytest
|
|
|
|
from photo_pipeline.jobs import locks
|
|
|
|
|
|
def test_broad_to_narrow_ranks():
|
|
assert locks.rank("library") < locks.rank("rename")
|
|
assert locks.rank("rename") < locks.rank("album")
|
|
assert locks.rank("album") < locks.rank("asset")
|
|
|
|
|
|
def test_acquiring_narrower_while_holding_broader_is_allowed():
|
|
locks.validate_acquisition(["library"], "asset") # no raise
|
|
locks.validate_acquisition(["library", "album"], "asset")
|
|
|
|
|
|
def test_acquiring_broader_while_holding_narrower_is_rejected():
|
|
with pytest.raises(locks.LockOrderError):
|
|
locks.validate_acquisition(["asset"], "library")
|
|
with pytest.raises(locks.LockOrderError):
|
|
locks.validate_acquisition(["album"], "rename")
|
|
|
|
|
|
def test_unknown_lock_is_rejected():
|
|
with pytest.raises(locks.LockOrderError):
|
|
locks.rank("nonsense")
|