def test_write_lock_while_read_locked(self): real_lock = DummyLock() l = CountedLock(real_lock) l.lock_read() self.assertRaises(ReadOnlyError, l.lock_write) self.assertRaises(ReadOnlyError, l.lock_write) l.unlock() self.assertFalse(l.is_locked()) self.assertEquals(['lock_read', 'unlock'], real_lock._calls)
def test_read_lock_while_write_locked(self): real_lock = DummyLock() l = CountedLock(real_lock) l.lock_write() l.lock_read() l.lock_write() l.unlock() l.unlock() l.unlock() self.assertFalse(l.is_locked()) self.assertEquals(['lock_write', 'unlock'], real_lock._calls)
def test_write_lock_while_read_locked(self): real_lock = DummyLock() l = CountedLock(real_lock) l.lock_read() self.assertRaises(ReadOnlyError, l.lock_write) self.assertRaises(ReadOnlyError, l.lock_write) l.unlock() self.assertFalse(l.is_locked()) self.assertEquals( ['lock_read', 'unlock'], real_lock._calls)
def test_read_lock_while_write_locked(self): real_lock = DummyLock() l = CountedLock(real_lock) l.lock_write() l.lock_read() self.assertEquals('token', l.lock_write()) l.unlock() l.unlock() l.unlock() self.assertFalse(l.is_locked()) self.assertEquals( ['lock_write', 'unlock'], real_lock._calls)
def test_lock_unlock(self): # Lock and unlock a counted lock real_lock = DummyLock() l = CountedLock(real_lock) self.assertFalse(l.is_locked()) # can lock twice, although this isn't allowed on the underlying lock l.lock_read() l.lock_read() self.assertTrue(l.is_locked()) # and release l.unlock() self.assertTrue(l.is_locked()) l.unlock() self.assertFalse(l.is_locked()) self.assertEquals(['lock_read', 'unlock'], real_lock._calls)
def test_read_lock(self): # Lock and unlock a counted lock real_lock = DummyLock() l = CountedLock(real_lock) self.assertFalse(l.is_locked()) # can lock twice, although this isn't allowed on the underlying lock l.lock_read() l.lock_read() self.assertTrue(l.is_locked()) # and release l.unlock() self.assertTrue(l.is_locked()) l.unlock() self.assertFalse(l.is_locked()) self.assertEquals( ['lock_read', 'unlock'], real_lock._calls)