diff options
Diffstat (limited to 'WebKitTools/Scripts/webkitpy/tool/bot')
-rw-r--r-- | WebKitTools/Scripts/webkitpy/tool/bot/queueengine.py | 12 | ||||
-rw-r--r-- | WebKitTools/Scripts/webkitpy/tool/bot/queueengine_unittest.py | 42 |
2 files changed, 44 insertions, 10 deletions
diff --git a/WebKitTools/Scripts/webkitpy/tool/bot/queueengine.py b/WebKitTools/Scripts/webkitpy/tool/bot/queueengine.py index 36cbc5f..289dc4a 100644 --- a/WebKitTools/Scripts/webkitpy/tool/bot/queueengine.py +++ b/WebKitTools/Scripts/webkitpy/tool/bot/queueengine.py @@ -33,7 +33,6 @@ import traceback from datetime import datetime, timedelta -from webkitpy.common.net.statusserver import StatusServer from webkitpy.common.system.executive import ScriptError from webkitpy.common.system.deprecated_logging import log, OutputTee @@ -117,10 +116,10 @@ class QueueEngine: message = "Unexpected failure when processing patch! Please file a bug against webkit-patch.\n%s" % e.message_with_output() self._delegate.handle_unexpected_error(work_item, message) except TerminateQueue, e: - log("\nTerminateQueue exception received.") + self._stopping("TerminateQueue exception received.") return 0 except KeyboardInterrupt, e: - log("\nUser terminated queue.") + self._stopping("User terminated queue.") return 1 except Exception, e: traceback.print_exc() @@ -129,6 +128,13 @@ class QueueEngine: # Never reached. self._ensure_work_log_closed() + def _stopping(self, message): + log("\n%s" % message) + self._delegate.stop_work_queue(message) + # Be careful to shut down our OutputTee or the unit tests will be unhappy. + self._ensure_work_log_closed() + self._output_tee.remove_log(self._queue_log) + def _begin_logging(self): self._queue_log = self._output_tee.add_log(self._delegate.queue_log_path()) self._work_log = None diff --git a/WebKitTools/Scripts/webkitpy/tool/bot/queueengine_unittest.py b/WebKitTools/Scripts/webkitpy/tool/bot/queueengine_unittest.py index ec91bdb..bfec401 100644 --- a/WebKitTools/Scripts/webkitpy/tool/bot/queueengine_unittest.py +++ b/WebKitTools/Scripts/webkitpy/tool/bot/queueengine_unittest.py @@ -34,7 +34,9 @@ import threading import unittest from webkitpy.common.system.executive import ScriptError -from webkitpy.tool.bot.queueengine import QueueEngine, QueueEngineDelegate +from webkitpy.common.system.outputcapture import OutputCapture +from webkitpy.tool.bot.queueengine import QueueEngine, QueueEngineDelegate, TerminateQueue + class LoggingDelegate(QueueEngineDelegate): def __init__(self, test): @@ -94,14 +96,19 @@ class LoggingDelegate(QueueEngineDelegate): self._test.assertEquals(work_item, "work_item") -class ThrowErrorDelegate(LoggingDelegate): - def __init__(self, test, error_code): +class RaisingDelegate(LoggingDelegate): + def __init__(self, test, exception): LoggingDelegate.__init__(self, test) - self.error_code = error_code + self._exception = exception + self.stop_message = None def process_work_item(self, work_item): self.record("process_work_item") - raise ScriptError(exit_code=self.error_code) + raise self._exception + + def stop_work_queue(self, message): + self.record("stop_work_queue") + self.stop_message = message class NotSafeToProceedDelegate(LoggingDelegate): @@ -132,7 +139,7 @@ class QueueEngineTest(unittest.TestCase): self.assertTrue(os.path.exists(os.path.join(self.temp_dir, "work_log_path", "work_item.log"))) def test_unexpected_error(self): - delegate = ThrowErrorDelegate(self, 3) + delegate = RaisingDelegate(self, ScriptError(exit_code=3)) work_queue = QueueEngine("error-queue", delegate, threading.Event()) work_queue.run() expected_callbacks = LoggingDelegate.expected_callbacks[:] @@ -143,11 +150,32 @@ class QueueEngineTest(unittest.TestCase): self.assertEquals(delegate._callbacks, expected_callbacks) def test_handled_error(self): - delegate = ThrowErrorDelegate(self, QueueEngine.handled_error_code) + 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) + def _test_terminating_queue(self, exception, expected_message): + work_item_index = LoggingDelegate.expected_callbacks.index('process_work_item') + # The terminating error should be handled right after process_work_item. + # There should be no other callbacks after stop_work_queue. + expected_callbacks = LoggingDelegate.expected_callbacks[:work_item_index + 1] + expected_callbacks.append("stop_work_queue") + + delegate = RaisingDelegate(self, exception) + work_queue = QueueEngine("terminating-queue", delegate, threading.Event()) + + output = OutputCapture() + expected_stderr = "\n%s\n" % expected_message + output.assert_outputs(self, work_queue.run, [], expected_stderr=expected_stderr) + + self.assertEquals(delegate._callbacks, expected_callbacks) + self.assertEquals(delegate.stop_message, expected_message) + + def test_terminating_error(self): + self._test_terminating_queue(KeyboardInterrupt(), "User terminated queue.") + self._test_terminating_queue(TerminateQueue(), "TerminateQueue exception received.") + def test_not_safe_to_proceed(self): delegate = NotSafeToProceedDelegate(self) work_queue = FastQueueEngine(delegate) |