Clean up ChunkedUpdateDrawingAreaProxy
[WebKit-https.git] / WebKitTools / Scripts / webkitpy / tool / bot / commitqueuetask_unittest.py
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 from datetime import datetime
30 import unittest
31
32 from webkitpy.common.system.deprecated_logging import error, log
33 from webkitpy.common.system.outputcapture import OutputCapture
34 from webkitpy.thirdparty.mock import Mock
35 from webkitpy.tool.bot.commitqueuetask import *
36 from webkitpy.tool.mocktool import MockTool
37
38
39 class MockCommitQueue(CommitQueueTaskDelegate):
40     def __init__(self, error_plan):
41         self._error_plan = error_plan
42
43     def run_command(self, command):
44         log("run_webkit_patch: %s" % command)
45         if self._error_plan:
46             error = self._error_plan.pop(0)
47             if error:
48                 raise error
49
50     def command_passed(self, success_message, patch):
51         log("command_passed: success_message='%s' patch='%s'" % (
52             success_message, patch.id()))
53
54     def command_failed(self, failure_message, script_error, patch):
55         log("command_failed: failure_message='%s' script_error='%s' patch='%s'" % (
56             failure_message, script_error, patch.id()))
57         return 3947
58
59     def refetch_patch(self, patch):
60         return patch
61
62     def layout_test_results(self):
63         return None
64
65     def report_flaky_tests(self, patch, flaky_tests):
66         log("report_flaky_tests: patch='%s' flaky_tests='%s'" % (patch.id(), flaky_tests))
67
68
69 class CommitQueueTaskTest(unittest.TestCase):
70     def _run_through_task(self, commit_queue, expected_stderr, expected_exception=None):
71         tool = MockTool(log_executive=True)
72         patch = tool.bugs.fetch_attachment(197)
73         task = CommitQueueTask(commit_queue, patch)
74         OutputCapture().assert_outputs(self, task.run, expected_stderr=expected_stderr, expected_exception=expected_exception)
75
76     def test_success_case(self):
77         commit_queue = MockCommitQueue([])
78         expected_stderr = """run_webkit_patch: ['clean']
79 command_passed: success_message='Cleaned working directory' patch='197'
80 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
81 command_passed: success_message='Applied patch' patch='197'
82 run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both']
83 command_passed: success_message='Built patch' patch='197'
84 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
85 command_passed: success_message='Passed tests' patch='197'
86 run_webkit_patch: ['land-attachment', '--force-clean', '--ignore-builders', '--non-interactive', '--parent-command=commit-queue', 197]
87 command_passed: success_message='Landed patch' patch='197'
88 """
89         self._run_through_task(commit_queue, expected_stderr)
90
91     def test_clean_failure(self):
92         commit_queue = MockCommitQueue([
93             ScriptError("MOCK clean failure"),
94         ])
95         expected_stderr = """run_webkit_patch: ['clean']
96 command_failed: failure_message='Unable to clean working directory' script_error='MOCK clean failure' patch='197'
97 """
98         self._run_through_task(commit_queue, expected_stderr)
99
100     def test_apply_failure(self):
101         commit_queue = MockCommitQueue([
102             None,
103             ScriptError("MOCK apply failure"),
104         ])
105         expected_stderr = """run_webkit_patch: ['clean']
106 command_passed: success_message='Cleaned working directory' patch='197'
107 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
108 command_failed: failure_message='Patch does not apply' script_error='MOCK apply failure' patch='197'
109 """
110         self._run_through_task(commit_queue, expected_stderr, ScriptError)
111
112     def test_build_failure(self):
113         commit_queue = MockCommitQueue([
114             None,
115             None,
116             ScriptError("MOCK build failure"),
117         ])
118         expected_stderr = """run_webkit_patch: ['clean']
119 command_passed: success_message='Cleaned working directory' patch='197'
120 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
121 command_passed: success_message='Applied patch' patch='197'
122 run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both']
123 command_failed: failure_message='Patch does not build' script_error='MOCK build failure' patch='197'
124 run_webkit_patch: ['build', '--force-clean', '--no-update', '--build-style=both']
125 command_passed: success_message='Able to build without patch' patch='197'
126 """
127         self._run_through_task(commit_queue, expected_stderr, ScriptError)
128
129     def test_red_build_failure(self):
130         commit_queue = MockCommitQueue([
131             None,
132             None,
133             ScriptError("MOCK build failure"),
134             ScriptError("MOCK clean build failure"),
135         ])
136         expected_stderr = """run_webkit_patch: ['clean']
137 command_passed: success_message='Cleaned working directory' patch='197'
138 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
139 command_passed: success_message='Applied patch' patch='197'
140 run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both']
141 command_failed: failure_message='Patch does not build' script_error='MOCK build failure' patch='197'
142 run_webkit_patch: ['build', '--force-clean', '--no-update', '--build-style=both']
143 command_failed: failure_message='Unable to build without patch' script_error='MOCK clean build failure' patch='197'
144 """
145         self._run_through_task(commit_queue, expected_stderr)
146
147     def test_flaky_test_failure(self):
148         commit_queue = MockCommitQueue([
149             None,
150             None,
151             None,
152             ScriptError("MOCK tests failure"),
153         ])
154         expected_stderr = """run_webkit_patch: ['clean']
155 command_passed: success_message='Cleaned working directory' patch='197'
156 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
157 command_passed: success_message='Applied patch' patch='197'
158 run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both']
159 command_passed: success_message='Built patch' patch='197'
160 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
161 command_failed: failure_message='Patch does not pass tests' script_error='MOCK tests failure' patch='197'
162 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
163 command_passed: success_message='Passed tests' patch='197'
164 report_flaky_tests: patch='197' flaky_tests='None'
165 run_webkit_patch: ['land-attachment', '--force-clean', '--ignore-builders', '--non-interactive', '--parent-command=commit-queue', 197]
166 command_passed: success_message='Landed patch' patch='197'
167 """
168         self._run_through_task(commit_queue, expected_stderr)
169
170     def test_test_failure(self):
171         commit_queue = MockCommitQueue([
172             None,
173             None,
174             None,
175             ScriptError("MOCK test failure"),
176             ScriptError("MOCK test failure again"),
177         ])
178         expected_stderr = """run_webkit_patch: ['clean']
179 command_passed: success_message='Cleaned working directory' patch='197'
180 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
181 command_passed: success_message='Applied patch' patch='197'
182 run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both']
183 command_passed: success_message='Built patch' patch='197'
184 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
185 command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure' patch='197'
186 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
187 command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure again' patch='197'
188 run_webkit_patch: ['build-and-test', '--force-clean', '--no-update', '--build', '--test', '--non-interactive']
189 command_passed: success_message='Able to pass tests without patch' patch='197'
190 """
191         self._run_through_task(commit_queue, expected_stderr, ScriptError)
192
193     def test_red_test_failure(self):
194         commit_queue = MockCommitQueue([
195             None,
196             None,
197             None,
198             ScriptError("MOCK test failure"),
199             ScriptError("MOCK test failure again"),
200             ScriptError("MOCK clean test failure"),
201         ])
202         expected_stderr = """run_webkit_patch: ['clean']
203 command_passed: success_message='Cleaned working directory' patch='197'
204 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
205 command_passed: success_message='Applied patch' patch='197'
206 run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both']
207 command_passed: success_message='Built patch' patch='197'
208 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
209 command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure' patch='197'
210 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
211 command_failed: failure_message='Patch does not pass tests' script_error='MOCK test failure again' patch='197'
212 run_webkit_patch: ['build-and-test', '--force-clean', '--no-update', '--build', '--test', '--non-interactive']
213 command_failed: failure_message='Unable to pass tests without patch (tree is red?)' script_error='MOCK clean test failure' patch='197'
214 """
215         self._run_through_task(commit_queue, expected_stderr)
216
217     def test_land_failure(self):
218         commit_queue = MockCommitQueue([
219             None,
220             None,
221             None,
222             None,
223             ScriptError("MOCK land failure"),
224         ])
225         expected_stderr = """run_webkit_patch: ['clean']
226 command_passed: success_message='Cleaned working directory' patch='197'
227 run_webkit_patch: ['apply-attachment', '--non-interactive', 197]
228 command_passed: success_message='Applied patch' patch='197'
229 run_webkit_patch: ['build', '--no-clean', '--no-update', '--build-style=both']
230 command_passed: success_message='Built patch' patch='197'
231 run_webkit_patch: ['build-and-test', '--no-clean', '--no-update', '--test', '--non-interactive']
232 command_passed: success_message='Passed tests' patch='197'
233 run_webkit_patch: ['land-attachment', '--force-clean', '--ignore-builders', '--non-interactive', '--parent-command=commit-queue', 197]
234 command_failed: failure_message='Unable to land patch' script_error='MOCK land failure' patch='197'
235 """
236         self._run_through_task(commit_queue, expected_stderr, ScriptError)