예제 #1
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())
예제 #2
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())
예제 #3
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)
예제 #4
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)
예제 #5
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()
예제 #6
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()
예제 #7
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())
예제 #8
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())