Skip to content

Commit

Permalink
Added test for acquire_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 authored Jun 24, 2020
1 parent 1a7ba4f commit e6a313d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_core_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,26 @@ def test_rlock_block(this_lock):

# Release lock, assert no owner
assert not this_lock._is_owned()

def test_rlock_acquire_timeout(this_lock):
from labthings.core.exceptions import LockError

# Acquire lock
assert this_lock.acquire()

# Override owner to force acquisition failure
this_lock._owner = None
print(this_lock._owner)
# Assert not owner
assert not this_lock._is_owned()

# Assert acquisition fails using context manager
with pytest.raises(LockError):
with this_lock.acquire_timeout(0.01):
pass

# Force ownership
this_lock._owner = getcurrent()

# Release lock
this_lock.release()

0 comments on commit e6a313d

Please sign in to comment.