|
1 # Copyright (C) 2010 Google Inc. All rights reserved. |
|
2 # |
|
3 # Redistribution and use in source and binary forms, with or without |
|
4 # modification, are permitted provided that the following conditions are |
|
5 # met: |
|
6 # |
|
7 # * Redistributions of source code must retain the above copyright |
|
8 # notice, this list of conditions and the following disclaimer. |
|
9 # * Redistributions in binary form must reproduce the above |
|
10 # copyright notice, this list of conditions and the following disclaimer |
|
11 # in the documentation and/or other materials provided with the |
|
12 # distribution. |
|
13 # * Neither the name of Google Inc. nor the names of its |
|
14 # contributors may be used to endorse or promote products derived from |
|
15 # this software without specific prior written permission. |
|
16 # |
|
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
|
29 import os |
|
30 import unittest |
|
31 |
|
32 from webkitpy.common.net.buildbot import Builder |
|
33 from webkitpy.common.system.outputcapture import OutputCapture |
|
34 from webkitpy.thirdparty.mock import Mock |
|
35 from webkitpy.tool.bot.sheriff import Sheriff |
|
36 from webkitpy.tool.mocktool import MockTool |
|
37 |
|
38 |
|
39 class MockSheriffBot(object): |
|
40 name = "mock-sheriff-bot" |
|
41 watchers = [ |
|
42 "watcher@example.com", |
|
43 ] |
|
44 |
|
45 def run_webkit_patch(self, args): |
|
46 return "Created bug https://bugs.webkit.org/show_bug.cgi?id=36936\n" |
|
47 |
|
48 |
|
49 class SheriffTest(unittest.TestCase): |
|
50 def test_rollout_reason(self): |
|
51 sheriff = Sheriff(MockTool(), MockSheriffBot()) |
|
52 builders = [ |
|
53 Builder("Foo", None), |
|
54 Builder("Bar", None), |
|
55 ] |
|
56 reason = "Caused builders Foo and Bar to fail." |
|
57 self.assertEquals(sheriff._rollout_reason(builders), reason) |
|
58 |
|
59 def test_post_blame_comment_on_bug(self): |
|
60 def run(): |
|
61 sheriff = Sheriff(MockTool(), MockSheriffBot()) |
|
62 builders = [ |
|
63 Builder("Foo", None), |
|
64 Builder("Bar", None), |
|
65 ] |
|
66 commit_info = Mock() |
|
67 commit_info.bug_id = lambda: None |
|
68 commit_info.revision = lambda: 4321 |
|
69 # Should do nothing with no bug_id |
|
70 sheriff.post_blame_comment_on_bug(commit_info, builders, []) |
|
71 sheriff.post_blame_comment_on_bug(commit_info, builders, [2468, 5646]) |
|
72 # Should try to post a comment to the bug, but MockTool.bugs does nothing. |
|
73 commit_info.bug_id = lambda: 1234 |
|
74 sheriff.post_blame_comment_on_bug(commit_info, builders, []) |
|
75 sheriff.post_blame_comment_on_bug(commit_info, builders, [3432]) |
|
76 sheriff.post_blame_comment_on_bug(commit_info, builders, [841, 5646]) |
|
77 |
|
78 expected_stderr = u"MOCK bug comment: bug_id=1234, cc=['watcher@example.com']\n--- Begin comment ---\\http://trac.webkit.org/changeset/4321 might have broken Foo and Bar\n--- End comment ---\n\nMOCK bug comment: bug_id=1234, cc=['watcher@example.com']\n--- Begin comment ---\\http://trac.webkit.org/changeset/4321 might have broken Foo and Bar\n--- End comment ---\n\nMOCK bug comment: bug_id=1234, cc=['watcher@example.com']\n--- Begin comment ---\\http://trac.webkit.org/changeset/4321 might have broken Foo and Bar\nThe following changes are on the blame list:\nhttp://trac.webkit.org/changeset/841\nhttp://trac.webkit.org/changeset/5646\n--- End comment ---\n\n" |
|
79 OutputCapture().assert_outputs(self, run, expected_stderr=expected_stderr) |
|
80 |
|
81 def test_provoke_flaky_builders(self): |
|
82 def run(): |
|
83 tool = MockTool() |
|
84 tool.buildbot.light_tree_on_fire() |
|
85 sheriff = Sheriff(tool, MockSheriffBot()) |
|
86 revisions_causing_failures = {} |
|
87 sheriff.provoke_flaky_builders(revisions_causing_failures) |
|
88 expected_stderr = "MOCK: force_build: name=Builder2, username=mock-sheriff-bot, comments=Probe for flakiness.\n" |
|
89 OutputCapture().assert_outputs(self, run, expected_stderr=expected_stderr) |
|
90 |
|
91 def test_post_blame_comment_on_bug(self): |
|
92 sheriff = Sheriff(MockTool(), MockSheriffBot()) |
|
93 builders = [ |
|
94 Builder("Foo", None), |
|
95 Builder("Bar", None), |
|
96 ] |
|
97 commit_info = Mock() |
|
98 commit_info.bug_id = lambda: None |
|
99 commit_info.revision = lambda: 4321 |
|
100 commit_info.committer = lambda: None |
|
101 commit_info.committer_email = lambda: "foo@example.com" |
|
102 commit_info.reviewer = lambda: None |
|
103 commit_info.author = lambda: None |
|
104 sheriff.post_automatic_rollout_patch(commit_info, builders) |
|
105 |