Skip to content

Commit e6a313d

Browse files
authored
Added test for acquire_timeout
1 parent 1a7ba4f commit e6a313d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_core_lock.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,26 @@ def test_rlock_block(this_lock):
8888

8989
# Release lock, assert no owner
9090
assert not this_lock._is_owned()
91+
92+
def test_rlock_acquire_timeout(this_lock):
93+
from labthings.core.exceptions import LockError
94+
95+
# Acquire lock
96+
assert this_lock.acquire()
97+
98+
# Override owner to force acquisition failure
99+
this_lock._owner = None
100+
print(this_lock._owner)
101+
# Assert not owner
102+
assert not this_lock._is_owned()
103+
104+
# Assert acquisition fails using context manager
105+
with pytest.raises(LockError):
106+
with this_lock.acquire_timeout(0.01):
107+
pass
108+
109+
# Force ownership
110+
this_lock._owner = getcurrent()
111+
112+
# Release lock
113+
this_lock.release()

0 commit comments

Comments
 (0)