def test_trivial(self): delegate = LoggingDelegate(self) work_queue = QueueEngine("trivial-queue", delegate, threading.Event()) work_queue.run() self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks) self.assertTrue(os.path.exists(os.path.join(self.temp_dir, "queue_log_path"))) self.assertTrue(os.path.exists(os.path.join(self.temp_dir, "work_log_path", "work_item.log")))
def test_handled_error(self): delegate = ThrowErrorDelegate(self, QueueEngine.handled_error_code) work_queue = QueueEngine("handled-error-queue", delegate, threading.Event()) work_queue.run() self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks)
def _run_engine(self, delegate, engine=None, termination_message=None): if not engine: engine = QueueEngine("test-queue", delegate, threading.Event()) if not termination_message: termination_message = "Delegate terminated queue." with OutputCapture(level=logging.INFO) as captured: engine.run() self.assertEqual(captured.root.log.getvalue(), '{}\n'.format(termination_message))
def test_unexpected_error(self): delegate = RaisingDelegate(self, ScriptError(exit_code=3)) work_queue = QueueEngine("error-queue", delegate, threading.Event()) work_queue.run() expected_callbacks = LoggingDelegate.expected_callbacks[:] work_item_index = expected_callbacks.index('process_work_item') # The unexpected error should be handled right after process_work_item starts # but before any other callback. Otherwise callbacks should be normal. expected_callbacks.insert(work_item_index + 1, 'handle_unexpected_error') self.assertEquals(delegate._callbacks, expected_callbacks)
def test_unexpected_error(self): delegate = ThrowErrorDelegate(self, 3) work_queue = QueueEngine("error-queue", delegate, threading.Event()) work_queue.run() expected_callbacks = LoggingDelegate.expected_callbacks[:] work_item_index = expected_callbacks.index('process_work_item') # The unexpected error should be handled right after process_work_item starts # but before any other callback. Otherwise callbacks should be normal. expected_callbacks.insert(work_item_index + 1, 'handle_unexpected_error') self.assertEquals(delegate._callbacks, expected_callbacks)
def test_handled_error(self): delegate = RaisingDelegate(self, ScriptError(exit_code=QueueEngine.handled_error_code)) work_queue = QueueEngine("handled-error-queue", delegate, threading.Event()) work_queue.run() self.assertEquals(delegate._callbacks, LoggingDelegate.expected_callbacks)