 Chromium Code Reviews
 Chromium Code Reviews Issue 2704663003:
  First version of benchmark health report.  (Closed)
    
  
    Issue 2704663003:
  First version of benchmark health report.  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 1 # Copyright 2017 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 datetime | |
| 6 import unittest | |
| 7 | |
| 8 import webapp2 | |
| 9 import webtest | |
| 10 | |
| 11 from google.appengine.ext import ndb | |
| 12 | |
| 13 from dashboard import benchmark_quality_report | |
| 14 from dashboard import update_test_suites | |
| 15 from dashboard.common import stored_object | |
| 16 from dashboard.common import testing_common | |
| 17 from dashboard.common import utils | |
| 18 from dashboard.models import anomaly | |
| 19 from dashboard.models import graph_data | |
| 20 from dashboard.models import sheriff | |
| 21 | |
| 22 | |
| 23 class BenchmarkQualityReportTest(testing_common.TestCase): | |
| 24 | |
| 25 def setUp(self): | |
| 26 super(BenchmarkQualityReportTest, self).setUp() | |
| 27 app = webapp2.WSGIApplication( | |
| 28 [('/benchmark_quality_report', | |
| 29 benchmark_quality_report.BenchmarkQualityReportHandler)]) | |
| 30 self.testapp = webtest.TestApp(app) | |
| 31 | |
| 32 def _AddAnomalyEntities( | |
| 33 self, revision_ranges, test_key, sheriff_key, bug_id=None): | |
| 34 """Adds a group of Anomaly entities to the datastore.""" | |
| 35 urlsafe_keys = [] | |
| 36 for start_rev, end_rev in revision_ranges: | |
| 37 anomaly_key = anomaly.Anomaly( | |
| 38 start_revision=start_rev, end_revision=end_rev, | |
| 39 test=test_key, bug_id=bug_id, sheriff=sheriff_key, | |
| 40 median_before_anomaly=100, median_after_anomaly=200).put() | |
| 41 urlsafe_keys.append(anomaly_key.urlsafe()) | |
| 42 return urlsafe_keys | |
| 43 | |
| 44 def _AddTests(self): | |
| 45 """Adds sample TestMetadata entities and returns their keys.""" | |
| 46 testing_common.AddTests(['ChromiumPerf'], ['linux'], { | |
| 47 'sunspider': { | |
| 48 'Total': {}, | |
| 49 'ref': {}, | |
| 50 }, | |
| 51 'page_cycler': { | |
| 52 'load_time': { | |
| 53 'cnn.com': {}, | |
| 54 'google.com': {}, | |
| 55 } | |
| 56 } | |
| 57 }) | |
| 58 tests = graph_data.TestMetadata.query() | |
| 59 for test in tests: | |
| 60 test.improvement_direction = anomaly.DOWN | |
| 61 ndb.put_multi(tests) | |
| 62 | |
| 63 def _AddSheriff(self, patterns): | |
| 64 """Adds a Sheriff entity and returns the key.""" | |
| 65 return sheriff.Sheriff( | |
| 66 id='Chromium Perf Sheriff', | |
| 67 email='sullivan@google.com', | |
| 68 patterns=patterns).put() | |
| 69 | |
| 70 def _AddCachedSuites(self): | |
| 71 test_suites = { | |
| 72 'sunspider': { | |
| 73 'mas': {'ChromiumPerf': {'mac': False, 'linux': False}}, | |
| 74 'mon': ['Total'], | |
| 75 }, | |
| 76 'page_cycler': { | |
| 77 'mas': {'ChromiumPerf': {'linux': False}, 'CrOS': {'foo': False}}, | |
| 78 'mon': ['load_time'], | |
| 79 }, | |
| 80 'speedometer': { | |
| 81 'mas': {'CrOS': {'foo': False}} | |
| 82 } | |
| 83 } | |
| 84 key = update_test_suites._NamespaceKey( | |
| 85 update_test_suites._LIST_SUITES_CACHE_KEY) | |
| 86 stored_object.Set(key, test_suites) | |
| 87 | |
| 88 def testGet(self): | |
| 89 response = self.testapp.get('/benchmark_quality_report') | |
| 90 self.assertEqual('text/html', response.content_type) | |
| 91 self.assertIn('Chrome Performance Dashboard', response.body) | |
| 92 | |
| 93 def testPost_MasterArgument_ListsTestsForMaster(self): | |
| 94 self._AddCachedSuites() | |
| 95 response = self.testapp.post( | |
| 96 '/benchmark_quality_report', {'master': 'CrOS'}) | |
| 97 benchmark_list = self.GetJsonValue(response, 'benchmarks') | |
| 98 self.assertItemsEqual(benchmark_list, ['page_cycler', 'speedometer']) | |
| 99 | |
| 100 def testPost_BenchmarkArgument_ListsAlertsAndBots(self): | |
| 101 self._AddCachedSuites() | |
| 102 self._AddSheriff(['*/*/page_cycler/*', '*/*/page_cycler/*/*']) | |
| 103 self._AddTests() | |
| 104 self._AddAnomalyEntities( | |
| 105 [(200, 400), (600, 800)], | |
| 106 utils.TestKey('ChromiumPerf/linux/page_cycler/load_time'), | |
| 107 ndb.Key('Sheriff', 'Chromium Perf Sheriff')) | |
| 108 self._AddAnomalyEntities( | |
| 109 [(500, 700)], | |
| 110 utils.TestKey('ChromiumPerf/linux/page_cycler/load_time/cnn.com'), | |
| 111 ndb.Key('Sheriff', 'Chromium Perf Sheriff')) | |
| 112 response = self.testapp.post( | |
| 113 '/benchmark_quality_report', { | |
| 114 'benchmark': 'page_cycler', | |
| 115 'num_days': '30', | |
| 
shatch
2017/02/17 18:03:47
Maybe add some anomalies outside of the num-days r
 
sullivan
2017/02/17 18:28:43
It's covered below in testPost_BenchmarkArgumentNu
 
shatch
2017/02/17 18:50:10
Oops :p
 | |
| 116 'master': 'ChromiumPerf', | |
| 117 }) | |
| 118 bots = self.GetJsonValue(response, 'bots') | |
| 119 self.assertItemsEqual(bots, ['linux']) | |
| 120 self.assertTrue(self.GetJsonValue(response, 'monitored')) | |
| 121 alerts = self.GetJsonValue(response, 'alerts') | |
| 122 self.assertEqual(3, len(alerts)) | |
| 123 | |
| 124 def testPost_Benchmark_NotMonitored(self): | |
| 125 self._AddCachedSuites() | |
| 126 self._AddTests() | |
| 127 response = self.testapp.post( | |
| 128 '/benchmark_quality_report', { | |
| 129 'benchmark': 'page_cycler', | |
| 130 'num_days': '30', | |
| 131 'master': 'ChromiumPerf', | |
| 132 }) | |
| 133 self.assertFalse(self.GetJsonValue(response, 'monitored')) | |
| 134 | |
| 135 def testPost_BenchmarkArgumentNumDaysArgument_ListsCorrectAlerts(self): | |
| 136 self._AddCachedSuites() | |
| 137 self._AddSheriff(['*/*/page_cycler/*', '*/*/page_cycler/*/*']) | |
| 138 self._AddTests() | |
| 139 self._AddAnomalyEntities( | |
| 140 [(200, 400), (600, 800)], | |
| 141 utils.TestKey('ChromiumPerf/linux/page_cycler/load_time'), | |
| 142 ndb.Key('Sheriff', 'Chromium Perf Sheriff')) | |
| 143 self._AddAnomalyEntities( | |
| 144 [(500, 700)], | |
| 145 utils.TestKey('ChromiumPerf/linux/page_cycler/load_time/cnn.com'), | |
| 146 ndb.Key('Sheriff', 'Chromium Perf Sheriff')) | |
| 147 anomalies = anomaly.Anomaly.query().fetch() | |
| 148 anomalies[0].timestamp = datetime.datetime.now() - datetime.timedelta( | |
| 149 days=20) | |
| 150 anomalies[0].put() | |
| 151 response = self.testapp.post( | |
| 152 '/benchmark_quality_report', | |
| 153 {'benchmark': 'page_cycler', 'num_days': '5', 'master': 'ChromiumPerf'}) | |
| 154 bots = self.GetJsonValue(response, 'bots') | |
| 155 self.assertItemsEqual(bots, ['linux']) | |
| 156 self.assertTrue(self.GetJsonValue(response, 'monitored')) | |
| 157 alerts = self.GetJsonValue(response, 'alerts') | |
| 158 self.assertEqual(2, len(alerts)) | |
| 159 | |
| 160 | |
| 161 if __name__ == '__main__': | |
| 162 unittest.main() | |
| OLD | NEW |