def test_reentrant_n(): test_lock = ReentrantRedLock('test_reentrant_n') for _ in range(10): assert test_lock.acquire() == True for _ in range(9): assert test_lock.release() == None assert test_lock.release() == True
def test_passthrough(self): test_lock = ReentrantRedLock('') test_lock.acquire() test_lock.release() self.redlock.assert_called_once_with('') self.redlock_acquire.assert_called_once_with() self.redlock_release.assert_called_once_with()
def test_reentrant_n(self): test_lock = ReentrantRedLock('') for _ in range(10): test_lock.acquire() for _ in range(10): test_lock.release() self.redlock.assert_called_once_with('') self.redlock_acquire.assert_called_once_with() self.redlock_release.assert_called_once_with()
def test_reentrant_acquire_and_extend(): test_lock = ReentrantRedLock("test_reentrant_acquire_and_extend", ttl=10000) # Acquire the lock normally assert test_lock.acquire() == True # We can acquire/extend it assert test_lock.acquire_and_extend() == True # Let the lock time out time.sleep(11) # We can acquire/extend it off the bat assert test_lock.acquire_and_extend() == True # Acquire it normally again assert test_lock.acquire() == True # We can still acquire/extend it assert test_lock.acquire_and_extend() == True # We should have reentered the lock twice (since it timed out) assert test_lock.release() == None assert test_lock.release() == None # And now we should actually be releasing the lock assert test_lock.release() == True
def test_reentrant_timeout(): test_lock = ReentrantRedLock('test_reentrant_timeout', ttl=5000) assert test_lock.acquire() == True time.sleep(6) assert test_lock.acquire() == True assert test_lock.release() == True
def test_reentrant(): test_lock = ReentrantRedLock('test_reentrant') assert test_lock.acquire() == True assert test_lock.acquire() == True assert test_lock.release() == None assert test_lock.release() == True
def test_passthrough(): test_lock = ReentrantRedLock('test_reentrant_passthrough') assert test_lock.acquire() == True test_lock.release() == True