From 7f52085e9a301c581f957f142d419c0fa6a2a503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Kro=CC=88ker?= Date: Sun, 17 Dec 2023 10:45:47 +0100 Subject: [PATCH] more tests --- tests/test_locking.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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):