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