Пример #1
0
 def test_write_lock_reentrant(self):
     real_lock = DummyLock()
     l = CountedLock(real_lock)
     self.assertEqual('token', l.lock_write())
     self.assertEqual('token', l.lock_write())
     l.unlock()
     l.unlock()
Пример #2
0
 def test_write_lock_reentrant(self):
     real_lock = DummyLock()
     l = CountedLock(real_lock)
     self.assertEqual('token', l.lock_write())
     self.assertEqual('token', l.lock_write())
     l.unlock()
     l.unlock()
Пример #3
0
 def test_break_lock(self):
     real_lock = DummyLock()
     l = CountedLock(real_lock)
     l.lock_write()
     l.lock_write()
     self.assertTrue(real_lock.is_locked())
     l.break_lock()
     self.assertFalse(l.is_locked())
     self.assertFalse(real_lock.is_locked())
Пример #4
0
 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)
Пример #5
0
 def test_reenter_with_token(self):
     real_lock = DummyLock()
     l1 = CountedLock(real_lock)
     l2 = CountedLock(real_lock)
     token = l1.lock_write()
     self.assertEqual('token', token)
     # now imagine that we lost that connection, but we still have the
     # token...
     del l1
     # because we can supply the token, we can acquire the lock through
     # another instance
     self.assertTrue(real_lock.is_locked())
     self.assertFalse(l2.is_locked())
     self.assertEqual(token, l2.lock_write(token=token))
     self.assertTrue(l2.is_locked())
     self.assertTrue(real_lock.is_locked())
     l2.unlock()
     self.assertFalse(l2.is_locked())
     self.assertFalse(real_lock.is_locked())
Пример #6
0
 def test_break_lock(self):
     real_lock = DummyLock()
     l = CountedLock(real_lock)
     l.lock_write()
     l.lock_write()
     self.assertTrue(real_lock.is_locked())
     l.break_lock()
     self.assertFalse(l.is_locked())
     self.assertFalse(real_lock.is_locked())
Пример #7
0
 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)
Пример #8
0
 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)
Пример #9
0
 def test_unlock_not_locked(self):
     real_lock = DummyLock()
     l = CountedLock(real_lock)
     self.assertRaises(LockNotHeld, l.unlock)
Пример #10
0
 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)
Пример #11
0
 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)
Пример #12
0
 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)
Пример #13
0
 def test_reenter_with_token(self):
     real_lock = DummyLock()
     l1 = CountedLock(real_lock)
     l2 = CountedLock(real_lock)
     token = l1.lock_write()
     self.assertEqual('token', token)
     # now imagine that we lost that connection, but we still have the
     # token...
     del l1
     # because we can supply the token, we can acquire the lock through
     # another instance
     self.assertTrue(real_lock.is_locked())
     self.assertFalse(l2.is_locked())
     self.assertEqual(token, l2.lock_write(token=token))
     self.assertTrue(l2.is_locked())
     self.assertTrue(real_lock.is_locked())
     l2.unlock()
     self.assertFalse(l2.is_locked())
     self.assertFalse(real_lock.is_locked())