diff --git a/tests/test_locking.py b/tests/test_locking.py index dc3e013..588d0e2 100644 --- a/tests/test_locking.py +++ b/tests/test_locking.py @@ -6,6 +6,32 @@ from dictdatabase import locking +def test_lock_release(): + lock = locking.WriteLock("db_release") + + with lock: + pass # Lock should be released here + + # Now, another lock should be able to be acquired + with locking.WriteLock("db_release"): + pass + + +def test_orphaned_lock_timeout(): + prev_timeout = locking.LOCK_TIMEOUT + locking.LOCK_TIMEOUT = 0.1 + lock = locking.WriteLock("db_orphaned") + + lock._lock() + time.sleep(0.2) + + # Trigger the removal of orphaned locks + ls = locking.FileLocksSnapshot(lock.need_lock) + assert len(ls.locks) == 0 + + locking.LOCK_TIMEOUT = prev_timeout + + def test_double_lock_exception(use_compression): name = "test_double_lock_exception" with pytest.raises(RuntimeError):