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")))
Exemple #2
0
 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."
     expected_logs = "\n%s\n" % termination_message
     OutputCapture().assert_outputs(self, engine.run, expected_logs=expected_logs)
Exemple #3
0
 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)
Exemple #4
0
    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 = 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_sleep_message(self):
     engine = QueueEngine("test", None, None)
     engine._now = lambda: datetime.datetime(2010, 1, 1)
     expected_sleep_message = "MESSAGE Sleeping until 2010-01-01 00:02:00 (2 mins)."
     self.assertEqual(engine._sleep_message("MESSAGE"),
                      expected_sleep_message)
 def test_now(self):
     """Make sure there are no typos in the QueueEngine.now() method."""
     engine = QueueEngine("test", None, None)
     self.assertIsInstance(engine._now(), datetime.datetime)