def test_partial_acquired_failure(self): lock1 = threading.Lock() lock2 = mock.create_autospec(threading.Lock()) lock2.acquire.side_effect = RuntimeError("Broke") n_lock = lock_utils.MultiLock((lock1, lock2)) self.assertRaises(threading.ThreadError, n_lock.acquire) self.assertEqual(1, n_lock.obtained) n_lock.release()
def mock_acked_message(ack_ok=True, **kwargs): msg = mock.create_autospec(message.Message, spec_set=True, instance=True, channel=None, **kwargs) def ack_side_effect(*args, **kwargs): msg.acknowledged = True if ack_ok: msg.ack_log_error.side_effect = ack_side_effect msg.acknowledged = False return msg
def test_partial_acquired(self): lock1 = threading.Lock() lock2 = mock.create_autospec(threading.Lock()) lock2.acquire.return_value = False n_lock = lock_utils.MultiLock((lock1, lock2)) with n_lock as gotten: self.assertFalse(gotten) self.assertTrue(lock1.locked()) self.assertEqual(1, n_lock.obtained) self.assertEqual(2, len(n_lock)) self.assertEqual(0, n_lock.obtained)
def test_release_failure(self): lock1 = threading.Lock() lock2 = mock.create_autospec(threading.Lock()) lock2.acquire.return_value = True lock2.release.side_effect = RuntimeError("Broke") n_lock = lock_utils.MultiLock((lock1, lock2)) self.assertTrue(n_lock.acquire()) self.assertEqual(2, n_lock.obtained) self.assertRaises(threading.ThreadError, n_lock.release) self.assertEqual(2, n_lock.obtained) lock2.release.side_effect = None n_lock.release() self.assertEqual(0, n_lock.obtained)