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

Side by Side Diff: scripts/slave/unittests/results_dashboard_test.py

Issue 12317053: Sends test results to new perf dashboard (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Addressed comments about unit test Created 7 years, 9 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
« no previous file with comments | « scripts/slave/runtest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """ Source file for results_dashboard testcases."""
7
8 import json
9 import os
10 import shutil
11 import tempfile
12 import unittest
13 import urllib
14 import urllib2
15
16 import test_env # pylint: disable=W0403,W0611
17
18 from slave import results_dashboard
19 from slave import slave_utils
20 from testing_support.super_mox import mox
21
22
23 class IsEncodedJson(mox.Comparator):
24 def __init__(self, expected_json):
25 self._json = expected_json
26
27 def equals(self, rhs):
28 rhs_json = urllib.unquote_plus(rhs.data.replace("data=", ""))
29 return sorted(json.loads(self._json)) == sorted(json.loads(rhs_json))
30
31 def __repr__(self):
32 return "<Is Request JSON %s>" % self._json
33
34
35 class ResultsDashboardTest(unittest.TestCase):
36 def setUp(self):
37 super(ResultsDashboardTest, self).setUp()
38 self.mox = mox.Mox()
39 self.build_dir = tempfile.mkdtemp()
40 os.makedirs(os.path.join(self.build_dir, results_dashboard.CACHE_DIR))
41 self.cache_filename = os.path.join(self.build_dir,
42 results_dashboard.CACHE_DIR,
43 results_dashboard.CACHE_FILENAME)
44
45 def tearDown(self):
46 self.mox.UnsetStubs()
47 shutil.rmtree(self.build_dir)
48
49 def _SendResults(self, send_results_args, expected_new_json, errors):
50 self.mox.UnsetStubs() # Needed for multiple calls from same test.
51 self.mox.StubOutWithMock(slave_utils, "GetActiveMaster")
52 slave_utils.GetActiveMaster().AndReturn("ChromiumPerf")
53 self.mox.StubOutWithMock(urllib2, "urlopen")
54 for json_line, error in zip(expected_new_json, errors):
55 if error:
56 urllib2.urlopen(IsEncodedJson(json_line)).AndRaise(error)
57 else:
58 urllib2.urlopen(IsEncodedJson(json_line))
59 self.mox.ReplayAll()
60 send_results_args.append(self.build_dir)
61 results_dashboard.SendResults(*send_results_args)
62 self.mox.VerifyAll()
63
64 def test_SingleLogLine(self):
65 args = [
66 "bar-summary.dat",
67 ['{"traces": {"baz": ["100.0", "5.0"]},'
68 ' "rev": "12345", "webkit_rev": "6789"}'],
69 "linux-release",
70 "foo",
71 "https://chrome-perf.googleplex.com"]
72 expected_new_json = [json.dumps([{
73 "master": "ChromiumPerf",
74 "bot": "linux-release",
75 "test": "foo/bar/baz",
76 "revision": "12345",
77 "value": "100.0",
78 "error": "5.0",
79 "supplemental_columns": {
80 "r_webkit_rev": "6789",
81 }}])]
82 errors = [None]
83 self._SendResults(args, expected_new_json, errors)
84
85 def test_MultipleLogLines(self):
86 args = [
87 "bar-summary.dat", [
88 '{"traces": {"baz": ["100.0", "5.0"]},'
89 ' "rev": "12345", "webkit_rev": "6789"}',
90 '{"traces": {"box": ["101.0", "4.0"]},'
91 ' "rev": "12345", "webkit_rev": "6789"}'],
92 "linux-release",
93 "foo",
94 "https://chrome-perf.googleplex.com"]
95 expected_new_json = [json.dumps([{
96 "master": "ChromiumPerf",
97 "bot": "linux-release",
98 "test": "foo/bar/baz",
99 "revision": "12345",
100 "value": "100.0",
101 "error": "5.0",
102 "supplemental_columns": {
103 "r_webkit_rev": "6789",
104 }}, {
105 "master": "ChromiumPerf",
106 "bot": "linux-release",
107 "test": "foo/bar/box",
108 "revision": "12345",
109 "value": "101.0",
110 "error": "4.0",
111 "supplemental_columns": {
112 "r_webkit_rev": "6789",
113 }}])]
114 errors = [None]
115 self._SendResults(args, expected_new_json, errors)
116
117 def test_ModifiedTraceNames(self):
118 args = [
119 "bar-summary.dat",
120 ['{"traces": {"bar": ["100.0", "5.0"], "bar_ref": ["99.0", "2.0"],'
121 ' "baz/y": ["101.0", "3.0"], "notchanged": ["102.0", "1.0"]},'
122 ' "rev": "12345", "webkit_rev": "6789"}'],
123 "linux-release",
124 "foo",
125 "https://chrome-perf.googleplex.com"]
126 expected_new_json = [json.dumps([{
127 "master": "ChromiumPerf",
128 "bot": "linux-release",
129 "test": "foo/bar",
130 "revision": "12345",
131 "value": "100.0",
132 "error": "5.0",
133 "supplemental_columns": {
134 "r_webkit_rev": "6789",
135 }},{
136 "master": "ChromiumPerf",
137 "bot": "linux-release",
138 "test": "foo/bar/ref",
139 "revision": "12345",
140 "value": "99.0",
141 "error": "2.0",
142 "supplemental_columns": {
143 "r_webkit_rev": "6789",
144 }}, {
145 "master": "ChromiumPerf",
146 "bot": "linux-release",
147 "test": "foo/bar/baz_y",
148 "revision": "12345",
149 "value": "101.0",
150 "error": "3.0",
151 "supplemental_columns": {
152 "r_webkit_rev": "6789",
153 }},{
154 "master": "ChromiumPerf",
155 "bot": "linux-release",
156 "test": "foo/bar/notchanged",
157 "revision": "12345",
158 "value": "102.0",
159 "error": "1.0",
160 "supplemental_columns": {
161 "r_webkit_rev": "6789",
162 }}])]
163 errors = [None]
164 self._SendResults(args, expected_new_json, errors)
165
166 def test_ByUrlGraph(self):
167 args = [
168 "bar_by_url-summary.dat",
169 ['{"traces": {"baz": ["100.0", "5.0"]},'
170 ' "rev": "12345", "webkit_rev": "6789"}'],
171 "linux-release",
172 "foo",
173 "https://chrome-perf.googleplex.com"]
174 expected_new_json = [json.dumps([{
175 "master": "ChromiumPerf",
176 "bot": "linux-release",
177 "test": "foo/bar/baz",
178 "revision": "12345",
179 "value": "100.0",
180 "error": "5.0",
181 "supplemental_columns": {
182 "r_webkit_rev": "6789",
183 }}])]
184 errors = [None]
185 self._SendResults(args, expected_new_json, errors)
186
187 def test_FailureRetried(self):
188 args = [
189 "bar-summary.dat",
190 ['{"traces": {"baz": ["100.0", "5.0"]},'
191 ' "rev": "12345", "webkit_rev": "6789"}'],
192 "linux-release",
193 "foo",
194 "https://chrome-perf.googleplex.com"]
195 expected_new_json = [json.dumps([{
196 "master": "ChromiumPerf",
197 "bot": "linux-release",
198 "test": "foo/bar/baz",
199 "revision": "12345",
200 "value": "100.0",
201 "error": "5.0",
202 "supplemental_columns": {
203 "r_webkit_rev": "6789",
204 }}])]
205 errors = [urllib2.URLError("reason")]
206 self._SendResults(args, expected_new_json, errors)
207 args2 = [
208 "bar-summary.dat",
209 ['{"traces": {"baz": ["101.0", "6.0"]},'
210 ' "rev": "12346", "webkit_rev": "6790"}'],
211 "linux-release",
212 "foo",
213 "https://chrome-perf.googleplex.com"]
214 expected_new_json.append(json.dumps([{
215 "master": "ChromiumPerf",
216 "bot": "linux-release",
217 "test": "foo/bar/baz",
218 "revision": "12346",
219 "value": "101.0",
220 "error": "6.0",
221 "supplemental_columns": {
222 "r_webkit_rev": "6790",
223 }
224 }]))
225 errors = [None, None]
226 self._SendResults(args2, expected_new_json, errors)
227
228 def test_SuccessNotRetried(self):
229 args = [
230 "bar-summary.dat",
231 ['{"traces": {"baz": ["100.0", "5.0"]},'
232 ' "rev": "12345", "webkit_rev": "6789"}'],
233 "linux-release",
234 "foo",
235 "https://chrome-perf.googleplex.com"]
236 expected_new_json = [json.dumps([{
237 "master": "ChromiumPerf",
238 "bot": "linux-release",
239 "test": "foo/bar/baz",
240 "revision": "12345",
241 "value": "100.0",
242 "error": "5.0",
243 "supplemental_columns": {
244 "r_webkit_rev": "6789",
245 }}])]
246 errors = [None]
247 self._SendResults(args, expected_new_json, errors)
248 args2 = [
249 "bar-summary.dat",
250 ['{"traces": {"baz": ["101.0", "6.0"]},'
251 ' "rev": "12346", "webkit_rev": "6790"}'],
252 "linux-release",
253 "foo",
254 "https://chrome-perf.googleplex.com"]
255 expected_new_json2 = [json.dumps([{
256 "master": "ChromiumPerf",
257 "bot": "linux-release",
258 "test": "foo/bar/baz",
259 "revision": "12346",
260 "value": "101.0",
261 "error": "6.0",
262 "supplemental_columns": {
263 "r_webkit_rev": "6790",
264 }
265 }])]
266 errors = [None]
267 self._SendResults(args2, expected_new_json2, errors)
268
269 def test_FailureCached(self):
270 args = [
271 "bar-summary.dat",
272 ['{"traces": {"baz": ["100.0", "5.0"]},'
273 ' "rev": "12345", "webkit_rev": "6789"}'],
274 "linux-release",
275 "foo",
276 "https://chrome-perf.googleplex.com"]
277 expected_new_json = [json.dumps([{
278 "master": "ChromiumPerf",
279 "bot": "linux-release",
280 "test": "foo/bar/baz",
281 "revision": "12345",
282 "value": "100.0",
283 "error": "5.0",
284 "supplemental_columns": {
285 "r_webkit_rev": "6789",
286 }}])]
287 errors = [urllib2.URLError("reason")]
288 self._SendResults(args, expected_new_json, errors)
289 cache_file = open(self.cache_filename, "rb")
290 actual_cache = cache_file.read()
James Simonsen 2013/03/04 19:03:24 I was hoping you'd call SendResults again here, bu
sullivan 2013/03/04 20:00:57 I do call SendResults() twice and check that it se
291 cache_file.close()
292 self.assertEqual(expected_new_json[0], actual_cache)
293
294
295 if __name__ == '__main__':
296 unittest.main()
OLDNEW
« no previous file with comments | « scripts/slave/runtest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698