From e6a313d6c788fcf3361fa6e0bbe105d671659c36 Mon Sep 17 00:00:00 2001 From: "Joel T. Collins" Date: Wed, 24 Jun 2020 17:09:39 +0100 Subject: [PATCH] Added test for acquire_timeout --- tests/test_core_lock.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_core_lock.py b/tests/test_core_lock.py index 26c9f808..26b36bb3 100644 --- a/tests/test_core_lock.py +++ b/tests/test_core_lock.py @@ -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()