Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from datetime import datetime | 5 from datetime import datetime |
| 6 from datetime import timedelta | 6 from datetime import timedelta |
| 7 | 7 |
| 8 from google.appengine.ext import ndb | 8 from google.appengine.ext import ndb |
| 9 import webapp2 | 9 import webapp2 |
| 10 | 10 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 self.assertEquals(200, response.status_int) | 129 self.assertEquals(200, response.status_int) |
| 130 self.assertEquals({'success': False}, response.json_body) | 130 self.assertEquals({'success': False}, response.json_body) |
| 131 | 131 |
| 132 def testSuccessfulTriage(self): | 132 def testSuccessfulTriage(self): |
| 133 build_url = buildbot.CreateBuildUrl( | 133 build_url = buildbot.CreateBuildUrl( |
| 134 self.master_name, self.builder_name, self.build_number_found) | 134 self.master_name, self.builder_name, self.build_number_found) |
| 135 response = self.test_app.get( | 135 response = self.test_app.get( |
| 136 '/triage-analysis', | 136 '/triage-analysis', |
| 137 params={'url': build_url, 'correct': True, 'format': 'json'}) | 137 params={'url': build_url, 'correct': True, 'format': 'json'}) |
| 138 self.assertEquals(200, response.status_int) | 138 self.assertEquals(200, response.status_int) |
| 139 self.assertEquals({'success': True}, response.json_body) | 139 self.assertEquals( |
| 140 {'success': True, 'num_duplicate_analyses': 0}, | |
|
lijeffrey
2016/06/27 20:38:22
nit: I would put this second field on a separate l
| |
| 141 response.json_body) | |
| 140 | 142 |
| 141 def testIncompleteTriage(self): | 143 def testIncompleteTriage(self): |
| 142 build_url = buildbot.CreateBuildUrl( | 144 build_url = buildbot.CreateBuildUrl( |
| 143 self.master_name, self.builder_name, self.build_number_incomplete) | 145 self.master_name, self.builder_name, self.build_number_incomplete) |
| 144 response = self.test_app.get( | 146 response = self.test_app.get( |
| 145 '/triage-analysis', | 147 '/triage-analysis', |
| 146 params={'url': build_url, 'correct': True, 'format': 'json'}) | 148 params={'url': build_url, 'correct': True, 'format': 'json'}) |
| 147 self.assertEquals(200, response.status_int) | 149 self.assertEquals(200, response.status_int) |
| 148 self.assertEquals({'success': False}, response.json_body) | 150 self.assertEquals( |
| 151 {'success': False, 'num_duplicate_analyses': 0}, | |
| 152 response.json_body) | |
| 153 | |
| 154 def testDuplicatePropertyWorksWhenNotDuplicate(self): | |
| 155 analysis = WfAnalysis.Get( | |
| 156 self.master_name, self.builder_name, self.build_number_found) | |
| 157 self.assertFalse(analysis.duplicate) | |
| 158 | |
| 159 def testDuplicatePropertyWorksWhenDuplicate(self): | |
| 160 analysis = WfAnalysis.Get( | |
| 161 self.master_name, self.builder_name, self.build_number_found) | |
| 162 analysis.result_status = result_status.FOUND_CORRECT_DUPLICATE | |
| 163 self.assertTrue(analysis.duplicate) | |
| 149 | 164 |
| 150 def testAnalysesMatch(self): | 165 def testAnalysesMatch(self): |
| 151 analysis_with_empty_failures = WfAnalysis.Create( | 166 analysis_with_empty_failures = WfAnalysis.Create( |
| 152 self.master_name, self.builder_name, 200) | 167 self.master_name, self.builder_name, 200) |
| 153 analysis_with_empty_failures.result = { | 168 analysis_with_empty_failures.result = { |
| 154 'failures': [] | 169 'failures': [] |
| 155 } | 170 } |
| 156 analysis_with_empty_failures.put() | 171 analysis_with_empty_failures.put() |
| 157 | 172 |
| 158 analysis_with_no_suspected_cls = WfAnalysis.Create( | 173 analysis_with_no_suspected_cls = WfAnalysis.Create( |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 self.assertFalse(triage_analysis._DoAnalysesMatch( | 372 self.assertFalse(triage_analysis._DoAnalysesMatch( |
| 358 analysis_with_tests_1, | 373 analysis_with_tests_1, |
| 359 analysis_with_tests_2)) | 374 analysis_with_tests_2)) |
| 360 | 375 |
| 361 def createAnalysis(self, build_number, build_start_time): | 376 def createAnalysis(self, build_number, build_start_time): |
| 362 analysis = WfAnalysis.Create( | 377 analysis = WfAnalysis.Create( |
| 363 self.master_name, self.builder_name, build_number) | 378 self.master_name, self.builder_name, build_number) |
| 364 analysis.result = { | 379 analysis.result = { |
| 365 'failures': [ | 380 'failures': [ |
| 366 { | 381 { |
| 367 'suspected_cls': [ | 382 'suspected_cls': self.suspected_cls, |
| 368 { | |
| 369 'revision': 'abc', | |
| 370 } | |
| 371 ], | |
| 372 'step_name': 'turing_test', | 383 'step_name': 'turing_test', |
| 373 } | 384 } |
| 374 ] | 385 ] |
| 375 } | 386 } |
| 376 analysis.result_status = result_status.FOUND_UNTRIAGED | 387 analysis.result_status = result_status.FOUND_UNTRIAGED |
| 377 analysis.build_start_time = build_start_time | 388 analysis.build_start_time = build_start_time |
| 378 analysis.status = analysis_status.COMPLETED | 389 analysis.status = analysis_status.COMPLETED |
| 390 analysis.suspected_cls = self.suspected_cls | |
| 379 analysis.put() | 391 analysis.put() |
| 380 return analysis | 392 return analysis |
| 381 | 393 |
| 382 def testGetDuplicateAnalysesTooEarly(self): | 394 def testGetDuplicateAnalysesTooEarly(self): |
| 383 # Yesterday, UTC Noon. | 395 # Yesterday, UTC Noon. |
| 384 original_time = (datetime.utcnow() - timedelta(days=1)).replace( | 396 original_time = (datetime.utcnow() - timedelta(days=1)).replace( |
| 385 hour=12, minute=0, second=0, microsecond=0) | 397 hour=12, minute=0, second=0, microsecond=0) |
| 386 analysis_original = self.createAnalysis(300, original_time) | 398 analysis_original = self.createAnalysis(300, original_time) |
| 387 | 399 |
| 388 # An earlier time, outside bounds. | 400 # An earlier time, outside bounds. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 original_time = datetime.utcnow().replace( | 452 original_time = datetime.utcnow().replace( |
| 441 hour=12, minute=0, second=0, microsecond=0) | 453 hour=12, minute=0, second=0, microsecond=0) |
| 442 analysis_original = self.createAnalysis(308, original_time) | 454 analysis_original = self.createAnalysis(308, original_time) |
| 443 | 455 |
| 444 # Create another analysis at the same time (also today). | 456 # Create another analysis at the same time (also today). |
| 445 self.createAnalysis(309, original_time) | 457 self.createAnalysis(309, original_time) |
| 446 | 458 |
| 447 self.assertEquals( | 459 self.assertEquals( |
| 448 len(triage_analysis._GetDuplicateAnalyses(analysis_original)), 0) | 460 len(triage_analysis._GetDuplicateAnalyses(analysis_original)), 0) |
| 449 | 461 |
| 450 def testTriageDuplicateResults(self): | 462 def testTriageDuplicateResultsFoundCorrectDuplicate(self): |
| 451 # Yesterday, UTC Noon. | 463 # Yesterday, UTC Noon. |
| 452 original_time = (datetime.utcnow() - timedelta(days=1)).replace( | 464 original_time = (datetime.utcnow() - timedelta(days=1)).replace( |
| 453 hour=12, minute=0, second=0, microsecond=0) | 465 hour=12, minute=0, second=0, microsecond=0) |
| 454 analysis_original = self.createAnalysis(310, original_time) | 466 analysis_original = self.createAnalysis(310, original_time) |
| 455 | 467 |
| 456 # Create another analysis at the same time (also yesterday). | 468 # Create another analysis at the same time (also yesterday). |
| 457 self.createAnalysis(311, original_time) | 469 self.createAnalysis(311, original_time) |
| 458 | 470 |
| 459 triage_analysis._TriageDuplicateResults(analysis_original, True) | 471 triage_analysis._TriageDuplicateResults(analysis_original, is_correct=True) |
| 460 | 472 |
| 461 second_analysis = WfAnalysis.Get(self.master_name, self.builder_name, 311) | 473 second_analysis = WfAnalysis.Get(self.master_name, self.builder_name, 311) |
| 462 | 474 |
| 463 self.assertEquals(result_status.NOT_FOUND_CORRECT, | 475 self.assertEquals(result_status.FOUND_CORRECT_DUPLICATE, |
| 464 second_analysis.result_status) | 476 second_analysis.result_status) |
| 465 | 477 |
| 478 def testTriageDuplicateResultsFoundIncorrectDuplicate(self): | |
| 479 # Yesterday, UTC Noon. | |
| 480 original_time = (datetime.utcnow() - timedelta(days=1)).replace( | |
| 481 hour=12, minute=0, second=0, microsecond=0) | |
| 482 analysis_original = self.createAnalysis(312, original_time) | |
| 483 | |
| 484 # Create another analysis at the same time (also yesterday). | |
| 485 self.createAnalysis(313, original_time) | |
| 486 | |
| 487 triage_analysis._TriageDuplicateResults(analysis_original, is_correct=False) | |
| 488 | |
| 489 second_analysis = WfAnalysis.Get(self.master_name, self.builder_name, 313) | |
| 490 | |
| 491 self.assertEquals(result_status.FOUND_INCORRECT_DUPLICATE, | |
| 492 second_analysis.result_status) | |
| OLD | NEW |