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 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 handle_script_error(cls, tool, state, script_error): is_svn_apply = script_error.command_name() == "svn-apply" status_id = cls._update_status_for_script_error(tool, state, script_error, is_error=is_svn_apply) if is_svn_apply: QueueEngine.exit_after_handled_error(script_error) message = "Attachment %s did not pass %s:\n\n%s\n\nIf any of these errors are false positives, please file a bug against check-webkit-style." % (state["patch"].id(), cls.name, script_error.message_with_output(output_limit=3*1024)) tool.bugs.post_comment_to_bug(state["patch"].bug_id(), message, cc=cls.watchers) exit(1)
def run_and_handle_errors(self, tool, options, state=None): if not state: state = {} try: self._run(tool, options, state) except CheckoutNeedsUpdate, e: log("Commit failed because the checkout is out of date. Please update and try again.") QueueEngine.exit_after_handled_error(e)
def handle_script_error(cls, tool, state, script_error): is_svn_apply = script_error.command_name() == "svn-apply" status_id = cls._update_status_for_script_error(tool, state, script_error, is_error=is_svn_apply) if is_svn_apply: QueueEngine.exit_after_handled_error(script_error) results_link = tool.status_server.results_url_for_status(status_id) message = "Attachment %s did not build on %s:\nBuild output: %s" % (state["patch"].id(), cls.port_name, results_link) tool.bugs.post_comment_to_bug(state["patch"].bug_id(), message, cc=cls.watchers) exit(1)
def run_and_handle_errors(self, tool, options, state=None): if not state: state = {} try: self._run(tool, options, state) except CheckoutNeedsUpdate, e: log("Commit failed because the checkout is out of date. Please update and try again.") log("You can pass --no-build to skip building/testing after update if you believe the new commits did not affect the results.") QueueEngine.exit_after_handled_error(e)
def run_and_handle_errors(self, tool, options, state=None): if not state: state = {} try: self._run(tool, options, state) except CheckoutNeedsUpdate, e: log("Commit failed because the checkout is out of date. Please update and try again." ) QueueEngine.exit_after_handled_error(e)
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 run_and_handle_errors(self, tool, options, state=None): if not state: state = {} try: self._run(tool, options, state) except CheckoutNeedsUpdate, e: log("Commit failed because the checkout is out of date. Please update and try again.") if options.parent_command: command = tool.command_by_name(options.parent_command) command.handle_checkout_needs_update(tool, state, options, e) QueueEngine.exit_after_handled_error(e)
def run_and_handle_errors(self, tool, options, state=None): if not state: state = {} try: self._run(tool, options, state) except CheckoutNeedsUpdate, e: log("Commit failed because the checkout is out of date. Please update and try again." ) if options.parent_command: command = tool.command_by_name(options.parent_command) command.handle_checkout_needs_update(tool, state, options, e) QueueEngine.exit_after_handled_error(e)
def handle_script_error(cls, tool, state, script_error): is_svn_apply = script_error.command_name() == "svn-apply" status_id = cls._update_status_for_script_error(tool, state, script_error, is_error=is_svn_apply) if is_svn_apply: QueueEngine.exit_after_handled_error(script_error) results_link = tool.status_server.results_url_for_status(status_id) message = "Attachment %s did not build on %s:\nBuild output: %s" % ( state["patch"].id(), cls.port_name, results_link) tool.bugs.post_comment_to_bug(state["patch"].bug_id(), message, cc=cls.watchers) exit(1)
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)
class StepSequence(object): def __init__(self, steps): self._steps = steps or [] def options(self): collected_options = [ steps.Options.parent_command, steps.Options.quiet, ] for step in self._steps: collected_options = collected_options + step.options() # Remove duplicates. collected_options = sorted(set(collected_options)) return collected_options def _run(self, tool, options, state): for step in self._steps: step(tool, options).run(state) def run_and_handle_errors(self, tool, options, state=None): if not state: state = {} try: self._run(tool, options, state) except CheckoutNeedsUpdate, e: log("Commit failed because the checkout is out of date. Please update and try again." ) QueueEngine.exit_after_handled_error(e) except ScriptError, e: if not options.quiet: log(e.message_with_output()) if options.parent_command: command = tool.command_by_name(options.parent_command) command.handle_script_error(tool, state, e) QueueEngine.exit_after_handled_error(e)
def run_and_handle_errors(self, tool, options, state=None): if not state: state = {} try: self._run(tool, options, state) except CheckoutNeedsUpdate as e: _log.info("Commit failed because the checkout is out of date. Please update and try again.") if options.parent_command: command = tool.command_by_name(options.parent_command) command.handle_checkout_needs_update(tool, state, options, e) QueueEngine.exit_after_handled_error(e) except ScriptError as e: if not options.quiet: _log.error(e.message_with_output(output_limit=5000)) if options.parent_command: command = tool.command_by_name(options.parent_command) command.handle_script_error(tool, state, e) QueueEngine.exit_after_handled_error(e)
def __init__(self, delegate): QueueEngine.__init__(self, "fast-queue", delegate, threading.Event())
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.assertTrue(isinstance(engine._now(), datetime.datetime))
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)
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)