Title: [89518] trunk/Tools
Revision
89518
Author
[email protected]
Date
2011-06-22 18:44:20 -0700 (Wed, 22 Jun 2011)

Log Message

2011-06-22  Eric Seidel  <[email protected]>

        Reviewed by Adam Barth.

        Make sheriff-bot robust against exceptions from commands
        https://bugs.webkit.org/show_bug.cgi?id=63211

        sheriff-bot was acting strange this afternoon.
        We don't know if this will fix the cause, but
        at least it adds some unit tests and catches
        one possible cause.

        * Scripts/webkitpy/tool/bot/sheriffircbot.py:
        * Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (89517 => 89518)


--- trunk/Tools/ChangeLog	2011-06-23 01:43:22 UTC (rev 89517)
+++ trunk/Tools/ChangeLog	2011-06-23 01:44:20 UTC (rev 89518)
@@ -1,3 +1,18 @@
+2011-06-22  Eric Seidel  <[email protected]>
+
+        Reviewed by Adam Barth.
+
+        Make sheriff-bot robust against exceptions from commands
+        https://bugs.webkit.org/show_bug.cgi?id=63211
+
+        sheriff-bot was acting strange this afternoon.
+        We don't know if this will fix the cause, but
+        at least it adds some unit tests and catches
+        one possible cause.
+
+        * Scripts/webkitpy/tool/bot/sheriffircbot.py:
+        * Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py:
+
 2011-06-22  Mark Rowe  <[email protected]>
 
         Reviewed by David Levin.

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py (89517 => 89518)


--- trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py	2011-06-23 01:43:22 UTC (rev 89517)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot.py	2011-06-23 01:44:20 UTC (rev 89518)
@@ -62,22 +62,27 @@
                                  self._message_queue,
                                  self._tool.wakeup_event)
 
-    def process_message(self, message):
-        (nick, request) = message
+    def _parse_command_and_args(self, request):
         tokenized_request = request.strip().split(" ")
-        if not tokenized_request:
-            return
         command = irc_command.commands.get(tokenized_request[0])
         args = tokenized_request[1:]
         if not command:
             # Give the peoples someone to talk with.
             command = irc_command.Eliza
             args = tokenized_request
-        response = command().execute(nick, args, self._tool, self._sheriff)
-        if response:
-            self._tool.irc().post(response)
+        return (command, args)
 
+    def process_message(self, requester_nick, request):
+        command, args = self._parse_command_and_args(request)
+        try:
+            response = command().execute(requester_nick, args, self._tool, self._sheriff)
+            if response:
+                self._tool.irc().post(response)
+        except Exception, e:
+            self._tool.irc().post("Exception executing command: %s" % e)
+
     def process_pending_messages(self):
         (messages, is_running) = self._message_queue.take_all()
         for message in messages:
-            self.process_message(message)
+            (nick, request) = message
+            self.process_message(nick, request)

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py (89517 => 89518)


--- trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py	2011-06-23 01:43:22 UTC (rev 89517)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/sheriffircbot_unittest.py	2011-06-23 01:44:20 UTC (rev 89518)
@@ -30,6 +30,7 @@
 import random
 
 from webkitpy.common.system.outputcapture import OutputCapture
+from webkitpy.tool.bot import irc_command
 from webkitpy.tool.bot.sheriff import Sheriff
 from webkitpy.tool.bot.sheriffircbot import SheriffIRCBot
 from webkitpy.tool.bot.sheriff_unittest import MockSheriffBot
@@ -45,6 +46,27 @@
 
 
 class SheriffIRCBotTest(unittest.TestCase):
+    def test_parse_command_and_args(self):
+        tool = MockTool()
+        bot = SheriffIRCBot(tool, Sheriff(tool, MockSheriffBot()))
+        self.assertEqual(bot._parse_command_and_args(""), (irc_command.Eliza, [""]))
+        self.assertEqual(bot._parse_command_and_args("   "), (irc_command.Eliza, [""]))
+        self.assertEqual(bot._parse_command_and_args(" hi "), (irc_command.Hi, []))
+        self.assertEqual(bot._parse_command_and_args(" hi there "), (irc_command.Hi, ["there"]))
+
+    def test_exception_during_command(self):
+        tool = MockTool()
+        tool.ensure_irc_connected(None)
+        bot = SheriffIRCBot(tool, Sheriff(tool, MockSheriffBot()))
+
+        class CommandWithException(object):
+            def execute(self, nick, args, tool, sheriff):
+                raise Exception("mock_exception")
+
+        bot._parse_command_and_args = lambda request: (CommandWithException, [])
+        expected_stderr = 'MOCK: irc.post: Exception executing command: mock_exception\n'
+        OutputCapture().assert_outputs(self, bot.process_message, args=["mock_nick", "ignored message"], expected_stderr=expected_stderr)
+
     def test_hi(self):
         random.seed(23324)
         expected_stderr = 'MOCK: irc.post: "Only you can prevent forest fires." -- Smokey the Bear\n'
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to