Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrd committed Dec 17, 2023
1 parent 5a38b61 commit 7f52085
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7f52085

Please sign in to comment.