Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import calendar | |
| 6 from datetime import datetime | |
| 7 import mock | |
| 8 | |
| 9 from testing_utils import testing | |
| 10 import webapp2 | |
| 11 | |
| 12 from common import time_util | |
| 13 from handlers import triage_suspected_cl | |
| 14 from model import analysis_approach_type | |
| 15 from model import result_status | |
| 16 from model import suspected_cl_status | |
| 17 from model.wf_analysis import WfAnalysis | |
| 18 from model.wf_suspected_cl import WfSuspectedCL | |
| 19 from waterfall import buildbot | |
| 20 | |
| 21 | |
| 22 class TriageSuspectedClTest(testing.AppengineTestCase): | |
| 23 app_module = webapp2.WSGIApplication([ | |
| 24 ('/triage-suspected-cl', triage_suspected_cl.TriageSuspectedCl), | |
| 25 ], debug=True) | |
| 26 | |
| 27 def setUp(self): | |
| 28 super(TriageSuspectedClTest, self).setUp() | |
| 29 self.master_name = 'm' | |
| 30 self.builder_name = 'b' | |
| 31 # self.build_number_incomplete = 120 # Analysis is not completed yet. | |
| 32 self.build_number_1 = 122 | |
| 33 self.build_number_2 = 123 | |
| 34 self.build_key_1 = '%s/%s/%d' % ( | |
| 35 self.master_name, self.builder_name, self.build_number_1) | |
| 36 self.build_key_2 = '%s/%s/%d' % ( | |
| 37 self.master_name, self.builder_name, self.build_number_2) | |
| 38 | |
| 39 self.repo_name = 'chromium' | |
| 40 self.revision_1 = 'r1' | |
| 41 self.commit_position = 123 | |
| 42 self.suspected_cl_1 = { | |
| 43 'repo_name': self.repo_name, | |
| 44 'revision': self.revision_1, | |
| 45 'commit_position': self.commit_position, | |
| 46 'url': 'https://codereview.chromium.org/123', | |
| 47 } | |
| 48 | |
| 49 self.revision_2 = 'r2' | |
| 50 self.suspected_cl_2 = { | |
| 51 'repo_name': self.repo_name, | |
| 52 'revision': self.revision_2, | |
| 53 'commit_position': 111, | |
| 54 'url': 'https://codereview.chromium.org/111', | |
| 55 } | |
| 56 | |
| 57 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | |
| 58 | |
| 59 def testSuccessfulTriage(self): | |
| 60 build_url = buildbot.CreateBuildUrl( | |
| 61 self.master_name, self.builder_name, self.build_number_1) | |
| 62 response = self.test_app.get( | |
| 63 '/triage-suspected-cl', | |
| 64 params={ | |
| 65 'url': build_url, | |
| 66 'status': '0', | |
| 67 'cl_info': 'chromium/rev1', | |
| 68 'format': 'json' | |
| 69 }) | |
| 70 self.assertEquals(200, response.status_int) | |
| 71 self.assertEquals( | |
| 72 { | |
| 73 'success': False | |
| 74 }, | |
| 75 response.json_body) | |
| 76 | |
| 77 def testUpdateSuspectedCLCorrect(self): | |
| 78 suspected_cl = WfSuspectedCL.Create( | |
| 79 self.repo_name, self.revision_1, self.commit_position) | |
| 80 | |
| 81 suspected_cl.builds = { | |
| 82 self.build_key_1: { | |
| 83 'failure_type': 'test', | |
| 84 'failures': { | |
| 85 's1': ['t1', 't2'] | |
| 86 }, | |
| 87 'status': None, | |
| 88 'approaches': [analysis_approach_type.HEURISTIC, | |
| 89 analysis_approach_type.TRY_JOB], | |
| 90 'top_score': None, | |
| 91 'Confidence': 80.0 | |
| 92 } | |
| 93 } | |
| 94 suspected_cl.put() | |
| 95 | |
| 96 cl_status = suspected_cl_status.CORRECT | |
| 97 triage_suspected_cl._UpdateSuspectedCL( | |
| 98 self.repo_name, self.revision_1, self.build_key_1, cl_status) | |
| 99 | |
| 100 suspected_cl = WfSuspectedCL.Get(self.repo_name, self.revision_1) | |
| 101 | |
| 102 self.assertEqual( | |
| 103 suspected_cl.builds[self.build_key_1]['status'], cl_status) | |
| 104 self.assertEqual( | |
| 105 suspected_cl.status, cl_status) | |
| 106 | |
| 107 | |
| 108 def testUpdateSuspectedCLIncorrect(self): | |
| 109 suspected_cl = WfSuspectedCL.Create( | |
| 110 self.repo_name, self.revision_1, self.commit_position) | |
| 111 | |
| 112 suspected_cl.builds = { | |
| 113 self.build_key_1: { | |
| 114 'failure_type': 'test', | |
| 115 'failures': { | |
| 116 's1': ['t1', 't2'] | |
| 117 }, | |
| 118 'status': None, | |
| 119 'approaches': [analysis_approach_type.HEURISTIC, | |
| 120 analysis_approach_type.TRY_JOB], | |
| 121 'top_score': None, | |
| 122 'Confidence': 80.0 | |
| 123 } | |
| 124 } | |
| 125 suspected_cl.put() | |
| 126 | |
| 127 cl_status = suspected_cl_status.INCORRECT | |
| 128 triage_suspected_cl._UpdateSuspectedCL( | |
| 129 self.repo_name, self.revision_1, self.build_key_1, cl_status) | |
| 130 | |
| 131 suspected_cl = WfSuspectedCL.Get(self.repo_name, self.revision_1) | |
| 132 | |
| 133 self.assertEqual( | |
| 134 suspected_cl.builds[self.build_key_1]['status'], cl_status) | |
| 135 self.assertEqual(suspected_cl.status, cl_status) | |
| 136 | |
| 137 | |
| 138 def testUpdateSuspectedCLPartially(self): | |
| 139 suspected_cl = WfSuspectedCL.Create( | |
| 140 self.repo_name, self.revision_1, self.commit_position) | |
| 141 | |
| 142 suspected_cl.builds = { | |
| 143 self.build_key_1: { | |
| 144 'failure_type': 'test', | |
| 145 'failures': { | |
| 146 's1': ['t1', 't2'] | |
| 147 }, | |
| 148 'status': None, | |
| 149 'approaches': [analysis_approach_type.HEURISTIC, | |
| 150 analysis_approach_type.TRY_JOB], | |
| 151 'top_score': None, | |
| 152 'Confidence': 80.0 | |
| 153 }, | |
| 154 self.build_key_2: { | |
| 155 'failure_type': 'test', | |
| 156 'failures': { | |
| 157 's1': ['t1', 't2'] | |
| 158 }, | |
| 159 'status': None, | |
| 160 'approaches': [analysis_approach_type.HEURISTIC, | |
| 161 analysis_approach_type.TRY_JOB], | |
| 162 'top_score': None, | |
| 163 'Confidence': 80.0 | |
| 164 } | |
| 165 } | |
| 166 suspected_cl.put() | |
| 167 | |
| 168 triage_suspected_cl._UpdateSuspectedCL( | |
| 169 self.repo_name, self.revision_1, self.build_key_1, | |
| 170 suspected_cl_status.CORRECT) | |
| 171 | |
| 172 suspected_cl = WfSuspectedCL.Get(self.repo_name, self.revision_1) | |
| 173 | |
| 174 self.assertEqual( | |
| 175 suspected_cl.builds[self.build_key_1]['status'], | |
| 176 suspected_cl_status.CORRECT) | |
| 177 self.assertEqual( | |
| 178 suspected_cl.status, suspected_cl_status.PARTIALLY_TRIAGED) | |
| 179 | |
| 180 triage_suspected_cl._UpdateSuspectedCL( | |
| 181 self.repo_name, self.revision_1, self.build_key_2, | |
| 182 suspected_cl_status.INCORRECT) | |
| 183 | |
| 184 suspected_cl = WfSuspectedCL.Get(self.repo_name, self.revision_1) | |
| 185 | |
| 186 self.assertEqual( | |
| 187 suspected_cl.builds[self.build_key_2]['status'], | |
| 188 suspected_cl_status.INCORRECT) | |
| 189 self.assertEqual( | |
| 190 suspected_cl.status, suspected_cl_status.PARTIALLY_CORRECT) | |
| 191 | |
| 192 def testUpdateAnalysisNone(self): | |
| 193 self.assertFalse(triage_suspected_cl._UpdateAnalysis( | |
| 194 self.master_name, self.builder_name, self.build_number_1, | |
| 195 self.repo_name, self.revision_1, None | |
| 196 )) | |
| 197 | |
| 198 def testUpdateAnalysisPartiallyTriaged(self): | |
| 199 analysis = WfAnalysis.Create( | |
| 200 self.master_name, self.builder_name, self.build_number_1) | |
| 201 | |
| 202 analysis.suspected_cls = [self.suspected_cl_1, self.suspected_cl_2] | |
| 203 analysis.result_status = result_status.FOUND_UNTRIAGED | |
| 204 analysis.put() | |
| 205 | |
| 206 success = triage_suspected_cl._UpdateAnalysis( | |
| 207 self.master_name, self.builder_name, self.build_number_1, | |
| 208 self.repo_name, self.revision_1, suspected_cl_status.CORRECT) | |
| 209 | |
| 210 expected_suspected_cls = [ | |
| 211 { | |
| 212 'repo_name': self.repo_name, | |
| 213 'revision': self.revision_1, | |
| 214 'commit_position': self.commit_position, | |
| 215 'url': 'https://codereview.chromium.org/123', | |
| 216 'status': suspected_cl_status.CORRECT | |
| 217 }, | |
| 218 self.suspected_cl_2 | |
| 219 ] | |
| 220 | |
| 221 analysis = WfAnalysis.Get( | |
| 222 self.master_name, self.builder_name, self.build_number_1) | |
| 223 self.assertTrue(success) | |
| 224 self.assertEqual(analysis.result_status, result_status.FOUND_UNTRIAGED) | |
| 225 self.assertEqual(analysis.suspected_cls, expected_suspected_cls) | |
| 226 | |
| 227 def testUpdateAnalysisAllCorrect(self): | |
| 228 analysis = WfAnalysis.Create( | |
| 229 self.master_name, self.builder_name, self.build_number_1) | |
| 230 | |
| 231 analysis.suspected_cls = [self.suspected_cl_1, self.suspected_cl_2] | |
| 232 analysis.result_status = result_status.FOUND_UNTRIAGED | |
| 233 analysis.put() | |
| 234 | |
| 235 triage_suspected_cl._UpdateAnalysis( | |
| 236 self.master_name, self.builder_name, self.build_number_1, | |
| 237 self.repo_name, self.revision_1, suspected_cl_status.CORRECT) | |
| 238 | |
| 239 triage_suspected_cl._UpdateAnalysis( | |
| 240 self.master_name, self.builder_name, self.build_number_1, | |
| 241 self.repo_name, self.revision_2, suspected_cl_status.CORRECT) | |
| 242 | |
| 243 analysis = WfAnalysis.Get( | |
| 244 self.master_name, self.builder_name, self.build_number_1) | |
| 245 self.assertEqual(analysis.result_status, result_status.FOUND_CORRECT) | |
| 246 | |
| 247 def testUpdateAnalysisAllIncorrect(self): | |
| 248 analysis = WfAnalysis.Create( | |
| 249 self.master_name, self.builder_name, self.build_number_1) | |
| 250 | |
| 251 analysis.suspected_cls = [self.suspected_cl_1, self.suspected_cl_2] | |
| 252 analysis.result_status = result_status.FOUND_UNTRIAGED | |
| 253 analysis.put() | |
| 254 | |
| 255 triage_suspected_cl._UpdateAnalysis( | |
| 256 self.master_name, self.builder_name, self.build_number_1, | |
| 257 self.repo_name, self.revision_1, suspected_cl_status.INCORRECT) | |
| 258 | |
| 259 triage_suspected_cl._UpdateAnalysis( | |
| 260 self.master_name, self.builder_name, self.build_number_1, | |
| 261 self.repo_name, self.revision_2, suspected_cl_status.INCORRECT) | |
| 262 | |
| 263 analysis = WfAnalysis.Get( | |
| 264 self.master_name, self.builder_name, self.build_number_1) | |
| 265 self.assertEqual(analysis.result_status, result_status.FOUND_INCORRECT) | |
| 266 | |
| 267 def testUpdateAnalysisPartiallyCorrect(self): | |
| 268 analysis = WfAnalysis.Create( | |
| 269 self.master_name, self.builder_name, self.build_number_1) | |
| 270 | |
| 271 analysis.suspected_cls = [self.suspected_cl_1, self.suspected_cl_2] | |
| 272 analysis.result_status = result_status.FOUND_UNTRIAGED | |
| 273 analysis.put() | |
| 274 | |
| 275 triage_suspected_cl._UpdateAnalysis( | |
| 276 self.master_name, self.builder_name, self.build_number_1, | |
| 277 self.repo_name, self.revision_1, suspected_cl_status.CORRECT) | |
| 278 | |
| 279 triage_suspected_cl._UpdateAnalysis( | |
| 280 self.master_name, self.builder_name, self.build_number_1, | |
| 281 self.repo_name, self.revision_2, suspected_cl_status.INCORRECT) | |
| 282 | |
| 283 analysis = WfAnalysis.Get( | |
| 284 self.master_name, self.builder_name, self.build_number_1) | |
| 285 self.assertEqual( | |
| 286 analysis.result_status, result_status.PARTIALLY_CORRECT_FOUND) | |
| 287 | |
| 288 @mock.patch.object(time_util, 'GetUTCNowTimestamp') | |
| 289 def testAppendTriageHistoryRecordWithHistory(self, mock_fn): | |
| 290 analysis = WfAnalysis.Create( | |
| 291 self.master_name, self.builder_name, self.build_number_1) | |
| 292 analysis.version = 'version' | |
| 293 analysis.triage_history = [{'some_info': True}] | |
| 294 analysis.put() | |
| 295 cl_info = '%s/%s' % (self.repo_name, self.revision_1) | |
| 296 time_delta = calendar.timegm(datetime(2016, 7, 1, 00, 00).timetuple()) | |
|
stgao
2016/10/06 00:29:51
nit: "time_delta" seems misleading
| |
| 297 mock_fn.return_value = time_delta | |
| 298 | |
| 299 triage_suspected_cl._AppendTriageHistoryRecord( | |
| 300 self.master_name, self.builder_name, self.build_number_1, | |
| 301 cl_info, suspected_cl_status.CORRECT, 'test') | |
| 302 analysis = WfAnalysis.Get( | |
| 303 self.master_name, self.builder_name, self.build_number_1) | |
| 304 | |
| 305 expected_history = [ | |
| 306 {'some_info': True}, | |
| 307 { | |
| 308 'triage_timestamp': time_delta, | |
| 309 'user_name': 'test', | |
| 310 'cl_status': suspected_cl_status.CORRECT, | |
| 311 'version': 'version', | |
| 312 'triaged_cl': cl_info | |
| 313 } | |
| 314 ] | |
| 315 self.assertEqual(analysis.triage_history, expected_history) | |
| 316 | |
| 317 @mock.patch.object(time_util, 'GetUTCNowTimestamp') | |
| 318 def testUpdateSuspectedCLAndAnalysis(self, mock_fn): | |
| 319 analysis = WfAnalysis.Create( | |
| 320 self.master_name, self.builder_name, self.build_number_1) | |
| 321 analysis.version = 'version' | |
| 322 analysis.suspected_cls = [ | |
| 323 self.suspected_cl_1 | |
| 324 ] | |
| 325 analysis.put() | |
| 326 | |
| 327 suspected_cl = WfSuspectedCL.Create( | |
| 328 self.repo_name, self.revision_1, self.commit_position) | |
| 329 suspected_cl.builds = { | |
| 330 self.build_key_1: { | |
| 331 'failure_type': 'test', | |
| 332 'failures': { | |
| 333 's1': ['t1', 't2'] | |
| 334 }, | |
| 335 'status': None, | |
| 336 'approaches': [analysis_approach_type.HEURISTIC, | |
| 337 analysis_approach_type.TRY_JOB], | |
| 338 'top_score': None, | |
| 339 'Confidence': 80.0 | |
| 340 } | |
| 341 } | |
| 342 suspected_cl.put() | |
| 343 | |
| 344 cl_info = '%s/%s' % (self.repo_name, self.revision_1) | |
| 345 | |
| 346 time_delta = calendar.timegm(datetime(2016, 7, 1, 00, 00).timetuple()) | |
|
stgao
2016/10/06 00:29:51
same here.
| |
| 347 mock_fn.return_value = time_delta | |
| 348 | |
| 349 success = triage_suspected_cl._UpdateSuspectedCLAndAnalysis( | |
| 350 self.master_name, self.builder_name, self.build_number_1, cl_info, | |
| 351 suspected_cl_status.CORRECT, 'test') | |
| 352 | |
| 353 self.assertTrue(success) | |
| OLD | NEW |