Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: appengine/findit/handlers/test/triage_analysis_test.py

Issue 2086113004: [Findit] Show build analysis references in UI for Findit Cross-platform auto-triage (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@build-matching
Patch Set: Merged with ("rebased" on) Issue 2029873002's code. Other changes. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 testing_utils import testing
lijeffrey 2016/06/27 20:38:22 I think you can leave this one where it was even t
josiahk 2016/06/28 22:59:23 Kept per conversation.
9 import webapp2 9 import webapp2
10 10
11 from testing_utils import testing
12
13 from handlers import triage_analysis 11 from handlers import triage_analysis
14 from model import analysis_status 12 from model import analysis_status
15 from model import result_status 13 from model import result_status
16 from model.wf_analysis import WfAnalysis 14 from model.wf_analysis import WfAnalysis
17 from waterfall import buildbot 15 from waterfall import buildbot
18 16
19 17
20 class TriageAnalysisTest(testing.AppengineTestCase): 18 class TriageAnalysisTest(testing.AppengineTestCase):
21 app_module = webapp2.WSGIApplication([ 19 app_module = webapp2.WSGIApplication([
22 ('/triage-analysis', triage_analysis.TriageAnalysis), 20 ('/triage-analysis', triage_analysis.TriageAnalysis),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 self.assertEquals(200, response.status_int) 127 self.assertEquals(200, response.status_int)
130 self.assertEquals({'success': False}, response.json_body) 128 self.assertEquals({'success': False}, response.json_body)
131 129
132 def testSuccessfulTriage(self): 130 def testSuccessfulTriage(self):
133 build_url = buildbot.CreateBuildUrl( 131 build_url = buildbot.CreateBuildUrl(
134 self.master_name, self.builder_name, self.build_number_found) 132 self.master_name, self.builder_name, self.build_number_found)
135 response = self.test_app.get( 133 response = self.test_app.get(
136 '/triage-analysis', 134 '/triage-analysis',
137 params={'url': build_url, 'correct': True, 'format': 'json'}) 135 params={'url': build_url, 'correct': True, 'format': 'json'})
138 self.assertEquals(200, response.status_int) 136 self.assertEquals(200, response.status_int)
139 self.assertEquals({'success': True}, response.json_body) 137 self.assertEquals(
138 {'success': True, 'num_duplicate_analyses': 0},
lijeffrey 2016/06/27 20:38:22 nit: put each field on a new line, same with the o
josiahk 2016/06/28 22:59:23 Done! Thanks!
139 response.json_body)
140 140
141 def testIncompleteTriage(self): 141 def testIncompleteTriage(self):
142 build_url = buildbot.CreateBuildUrl( 142 build_url = buildbot.CreateBuildUrl(
143 self.master_name, self.builder_name, self.build_number_incomplete) 143 self.master_name, self.builder_name, self.build_number_incomplete)
144 response = self.test_app.get( 144 response = self.test_app.get(
145 '/triage-analysis', 145 '/triage-analysis',
146 params={'url': build_url, 'correct': True, 'format': 'json'}) 146 params={'url': build_url, 'correct': True, 'format': 'json'})
147 self.assertEquals(200, response.status_int) 147 self.assertEquals(200, response.status_int)
148 self.assertEquals({'success': False}, response.json_body) 148 self.assertEquals(
149 {'success': False, 'num_duplicate_analyses': 0},
150 response.json_body)
151
152 def testDuplicatePropertyWorksWhenNotDuplicate(self):
lijeffrey 2016/06/27 20:38:22 nit: you can name this testDuplicatePropertyNoDup
josiahk 2016/06/28 22:59:23 Thanks!
153 analysis = WfAnalysis.Get(
154 self.master_name, self.builder_name, self.build_number_found)
155 self.assertFalse(analysis.is_duplicate)
156
157 def testDuplicatePropertyWorksWhenDuplicate(self):
158 analysis = WfAnalysis.Get(
159 self.master_name, self.builder_name, self.build_number_found)
160 analysis.result_status = result_status.FOUND_CORRECT_DUPLICATE
161 self.assertTrue(analysis.is_duplicate)
149 162
150 def testAnalysesMatch(self): 163 def testAnalysesMatch(self):
151 analysis_with_empty_failures = WfAnalysis.Create( 164 analysis_with_empty_failures = WfAnalysis.Create(
152 self.master_name, self.builder_name, 200) 165 self.master_name, self.builder_name, 200)
153 analysis_with_empty_failures.result = { 166 analysis_with_empty_failures.result = {
154 'failures': [] 167 'failures': []
155 } 168 }
156 analysis_with_empty_failures.put() 169 analysis_with_empty_failures.put()
157 170
158 analysis_with_no_suspected_cls = WfAnalysis.Create( 171 analysis_with_no_suspected_cls = WfAnalysis.Create(
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 self.assertFalse(triage_analysis._DoAnalysesMatch( 370 self.assertFalse(triage_analysis._DoAnalysesMatch(
358 analysis_with_tests_1, 371 analysis_with_tests_1,
359 analysis_with_tests_2)) 372 analysis_with_tests_2))
360 373
361 def _createAnalysis(self, build_number, build_start_time): 374 def _createAnalysis(self, build_number, build_start_time):
362 analysis = WfAnalysis.Create( 375 analysis = WfAnalysis.Create(
363 self.master_name, self.builder_name, build_number) 376 self.master_name, self.builder_name, build_number)
364 analysis.result = { 377 analysis.result = {
365 'failures': [ 378 'failures': [
366 { 379 {
367 'suspected_cls': [ 380 'suspected_cls': self.suspected_cls,
368 {
369 'revision': 'abc',
370 }
371 ],
372 'step_name': 'step_4', 381 'step_name': 'step_4',
373 } 382 }
374 ] 383 ]
375 } 384 }
376 analysis.result_status = result_status.FOUND_UNTRIAGED 385 analysis.result_status = result_status.FOUND_UNTRIAGED
377 analysis.build_start_time = build_start_time 386 analysis.build_start_time = build_start_time
378 analysis.status = analysis_status.COMPLETED 387 analysis.status = analysis_status.COMPLETED
388 analysis.suspected_cls = self.suspected_cls
379 analysis.put() 389 analysis.put()
380 return analysis 390 return analysis
381 391
382 def testGetDuplicateAnalysesTooEarly(self): 392 def testGetDuplicateAnalysesTooEarly(self):
383 # Two days ago, UTC Noon. 393 # Two days ago, UTC Noon.
384 original_time = (datetime.utcnow() - timedelta(days=2)).replace( 394 original_time = (datetime.utcnow() - timedelta(days=2)).replace(
385 hour=12, minute=0, second=0, microsecond=0) 395 hour=12, minute=0, second=0, microsecond=0)
386 analysis_original = self._createAnalysis(300, original_time) 396 analysis_original = self._createAnalysis(300, original_time)
387 397
388 # An earlier time, outside bounds. 398 # An earlier time, outside bounds.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 original_time = (datetime.utcnow() + timedelta(days=1)).replace( 450 original_time = (datetime.utcnow() + timedelta(days=1)).replace(
441 hour=12, minute=0, second=0, microsecond=0) 451 hour=12, minute=0, second=0, microsecond=0)
442 analysis_original = self._createAnalysis(308, original_time) 452 analysis_original = self._createAnalysis(308, original_time)
443 453
444 # Create another analysis at the same time (also tomorrow). 454 # Create another analysis at the same time (also tomorrow).
445 self._createAnalysis(309, original_time) 455 self._createAnalysis(309, original_time)
446 456
447 self.assertEquals( 457 self.assertEquals(
448 len(triage_analysis._GetDuplicateAnalyses(analysis_original)), 0) 458 len(triage_analysis._GetDuplicateAnalyses(analysis_original)), 0)
449 459
450 def testTriageDuplicateResults(self): 460 def testTriageDuplicateResultsFoundCorrectDuplicate(self):
451 # Two days ago, UTC Noon. 461 # Two days ago, UTC Noon.
452 original_time = (datetime.utcnow() - timedelta(days=2)).replace( 462 original_time = (datetime.utcnow() - timedelta(days=2)).replace(
453 hour=12, minute=0, second=0, microsecond=0) 463 hour=12, minute=0, second=0, microsecond=0)
454 analysis_original = self._createAnalysis(310, original_time) 464 analysis_original = self._createAnalysis(310, original_time)
455 465
456 # Create another analysis at the same time (also two days ago). 466 # Create another analysis at the same time (also two days ago).
457 self._createAnalysis(311, original_time) 467 self._createAnalysis(311, original_time)
458 468
459 triage_analysis._TriageDuplicateResults(analysis_original, True) 469 triage_analysis._TriageDuplicateResults(analysis_original, is_correct=True)
460 470
461 second_analysis = WfAnalysis.Get(self.master_name, self.builder_name, 311) 471 second_analysis = WfAnalysis.Get(self.master_name, self.builder_name, 311)
462 472
463 self.assertEquals(result_status.NOT_FOUND_CORRECT, 473 self.assertEquals(result_status.FOUND_CORRECT_DUPLICATE,
464 second_analysis.result_status) 474 second_analysis.result_status)
465 475
476 def testTriageDuplicateResultsFoundIncorrectDuplicate(self):
477 # Two days ago, UTC Noon.
478 original_time = (datetime.utcnow() - timedelta(days=2)).replace(
479 hour=12, minute=0, second=0, microsecond=0)
480 analysis_original = self._createAnalysis(312, original_time)
481
482 # Create another analysis at the same time (also two days ago).
483 self._createAnalysis(313, original_time)
lijeffrey 2016/06/27 20:38:22 why not make the second analysis a slightly later
josiahk 2016/06/28 22:59:23 Done!
484
485 triage_analysis._TriageDuplicateResults(analysis_original, is_correct=False)
486
487 second_analysis = WfAnalysis.Get(self.master_name, self.builder_name, 313)
488
489 self.assertEquals(result_status.FOUND_INCORRECT_DUPLICATE,
490 second_analysis.result_status)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698