def test_basic(self): timeout = 10 lock = Lock('basic', timeout=timeout) assert lock.held is False assert lock.seconds_remaining is 0 assert lock.acquire() is True assert timeout > lock.seconds_remaining > (timeout - 0.1) assert lock.held is True assert lock.acquire() is True # ensure reentrancy assert lock.release() is True assert lock.seconds_remaining is 0 assert lock.held is False assert lock.release() is False
def try_lock(item): """ Attempt to immedately acquire a lock on the timeline at key, returning the lock if it can be acquired, otherwise returning ``None``. """ key, timestamp = item lock = Lock(make_timeline_key(self.namespace, key), timeout=5, nowait=True) return lock if lock.acquire() else None, item
def test_basic(self): timeout = 10 lock = Lock('basic', timeout=timeout) assert lock.held is False assert lock.seconds_remaining is 0 assert lock.acquire() is True assert timeout > lock.seconds_remaining > (timeout - 0.1) assert lock.held is True with pytest.raises(LockAlreadyHeld): lock.acquire() assert lock.release() is True assert lock.seconds_remaining is 0 assert lock.held is False assert lock.release() is False