Skip to content

Commit

Permalink
Add more locking unit tests
Browse files Browse the repository at this point in the history
Took a few tests from #216.
  • Loading branch information
bmerry committed Sep 25, 2018
1 parent 84a397c commit ed36fff
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3987,6 +3987,26 @@ def test_lock_nonblocking(self):
lock2 = self.redis.lock('foo')
self.assertFalse(lock2.acquire(blocking=False))

def test_lock_twice(self):
lock = self.redis.lock('foo')
self.assertTrue(lock.acquire(blocking=False))
self.assertFalse(lock.acquire(blocking=False))

def test_acquiring_lock_different_lock_release(self):
lock1 = self.redis.lock('foo')
lock2 = self.redis.lock('foo')
self.assertTrue(lock1.acquire(blocking=False))
self.assertFalse(lock2.acquire(blocking=False))

# Test only releasing lock1 actually releases the lock
with self.assertRaises(redis.exceptions.LockError):
lock2.release()
self.assertFalse(lock2.acquire(blocking=False))
lock1.release()
# Locking with lock2 now has the lock
self.assertTrue(lock2.acquire(blocking=False))
self.assertFalse(lock1.acquire(blocking=False))

def test_lock_extend(self):
lock = self.redis.lock('foo', timeout=2)
lock.acquire()
Expand Down

0 comments on commit ed36fff

Please sign in to comment.