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

Side by Side Diff: infra/tools/builder_alerts/test/buildbot_test.py

Issue 475943002: Add time and state to builder revision data (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Add tests and address comments Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 shutil 5 import shutil
6 import tempfile 6 import tempfile
7 import unittest 7 import unittest
8 import pdb
eseidel 2014/08/18 16:35:43 ?
leviw_travelin_and_unemployed 2014/08/18 18:39:02 Whoops!
8 9
9 from infra.tools.builder_alerts import buildbot 10 from infra.tools.builder_alerts import buildbot
10 11
11 12
12 class BuildCacheTest(unittest.TestCase): 13 class BuildCacheTest(unittest.TestCase):
13 def setUp(self): 14 def setUp(self):
14 self.cache_path = tempfile.mkdtemp() 15 self.cache_path = tempfile.mkdtemp()
15 16
16 def tearDown(self): 17 def tearDown(self):
17 shutil.rmtree(self.cache_path, ignore_errors=True) 18 shutil.rmtree(self.cache_path, ignore_errors=True)
18 19
19 def test_build_cache(self): 20 def test_build_cache(self):
20 cache = buildbot.BuildCache(self.cache_path) 21 cache = buildbot.BuildCache(self.cache_path)
21 22
22 test_key = 'foo/bar' 23 test_key = 'foo/bar'
23 self.assertFalse(cache.has(test_key)) 24 self.assertFalse(cache.has(test_key))
24 25
25 test_data = ['test'] 26 test_data = ['test']
26 cache.set(test_key, test_data) 27 cache.set(test_key, test_data)
27 # Set it a second time to hit the "already there" case. 28 # Set it a second time to hit the "already there" case.
28 cache.set(test_key, test_data) 29 cache.set(test_key, test_data)
29 30
30 self.assertTrue(cache.has(test_key)) 31 self.assertTrue(cache.has(test_key))
31 self.assertEquals(cache.get(test_key), test_data) 32 self.assertEquals(cache.get(test_key), test_data)
32 33
33 self.assertIsNone(cache.get('does_not_exist')) 34 self.assertIsNone(cache.get('does_not_exist'))
34 self.assertIsNotNone(cache.key_age(test_key)) 35 self.assertIsNotNone(cache.key_age(test_key))
35 36
37 def test_latest_builder_info_for_master(self):
38 k_example_master_json = {
39 "builders": {
40 "Win Builder": {
41 "basedir": "Win_Builder",
42 "cachedBuilds": [
43 0,
44 1770,
45 1771
46 ],
47 "category": "2windows",
48 "currentBuilds": [
49 1772
50 ],
51 "pendingBuilds": 7,
52 "slaves": [
53 "build2-m1"
54 ],
55 "state": "building"
56 }
57 }
58 }
59
60 def mock_fetch_build_json(cache, master_url, builder_name, build_number):
61 k_example_build_json = {
62 "blame": [
63 "alexhenrie24@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98",
64 "yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98"
65 ],
66 "builderName": "Win Builder",
67 "currentStep": None,
68 "eta": None,
69 "number": 1771,
70 "properties": [
71 [
72 "build_archive_url",
73 "gs://chromium-win-archive/chromium.win/Win Builder/full-build-win32 _289623.zip",
74 "Annotation(package build)"
75 ],
76 [
77 "buildbotURL",
78 "http://build.chromium.org/p/chromium.win/",
79 "master.cfg"
80 ],
81 [
82 "buildername",
83 "Win Builder",
84 "Builder"
85 ],
86 [
87 "buildnumber",
88 1771,
89 "Build"
90 ],
91 [
92 "git_revision",
93 "7ddb6d39574175cdd237eca54537e84fb960d3b8",
94 "Change"
95 ],
96 [
97 "got_nacl_revision",
98 13611,
99 "Annotation(bot_update)"
100 ],
101 [
102 "got_nacl_revision_git",
103 "570e50beb76a2bdf6be4b345cbd47f225caf90af",
104 "Annotation(bot_update)"
105 ],
106 [
107 "got_revision",
108 289623,
109 "Annotation(bot_update)"
110 ],
111 [
112 "got_revision_git",
113 "7ddb6d39574175cdd237eca54537e84fb960d3b8",
114 "Annotation(bot_update)"
115 ],
116 [
117 "got_swarming_client_revision",
118 "bbf1fcca7932d92cca9d7dab46ea271a7f6d61fb",
119 "Annotation(bot_update)"
120 ],
121 [
122 "got_v8_revision",
123 23117,
124 "Annotation(bot_update)"
125 ],
126 [
127 "got_v8_revision_git",
128 "f284b29e37d97d7ee9128055862179dcbda7e398",
129 "Annotation(bot_update)"
130 ],
131 [
132 "got_webkit_revision",
133 180191,
134 "Annotation(bot_update)"
135 ],
136 [
137 "got_webkit_revision_git",
138 "9df9a9e66fed3921ec1f620f92ea7333a9c18122",
139 "Annotation(bot_update)"
140 ],
141 [
142 "got_webrtc_revision",
143 6886,
144 "Annotation(bot_update)"
145 ],
146 [
147 "got_webrtc_revision_git",
148 "c2ef523233552340785557abce1129a0f61537eb",
149 "Annotation(bot_update)"
150 ],
151 [
152 "mastername",
153 "chromium.win",
154 "master.cfg"
155 ]
156 ],
157 "steps": [
158 {
159 "eta": None,
160 "expectations": [
161 [
162 "output",
163 863225,
164 748982.2582168579
165 ]
166 ],
167 "hidden": False,
168 "isFinished": True,
169 "isStarted": True,
170 "logs": [
171 [
172 "preamble",
173 "http://build.chromium.org/p/chromium.win/builders/Win%20Builder /builds/1771/steps/steps/logs/preamble"
174 ],
175 [
176 "stdio",
177 "http://build.chromium.org/p/chromium.win/builders/Win%20Builder /builds/1771/steps/steps/logs/stdio"
178 ]
179 ],
180 "name": "steps",
181 "results": [
182 0,
183 []
184 ],
185 "step_number": 0,
186 "text": [
187 "running steps via annotated script"
188 ],
189 "times": [
190 3.3,
191 4.4
192 ],
193 "urls": {}
194 },
195 {
196 "eta": None,
197 "expectations": [],
198 "hidden": False,
199 "isFinished": True,
200 "isStarted": True,
201 "logs": [
202 [
203 "stdio",
204 "http://build.chromium.org/p/chromium.win/builders/Win%20Builder /builds/1771/steps/setup_build/logs/stdio"
205 ],
206 [
207 "run_recipe",
208 "http://build.chromium.org/p/chromium.win/builders/Win%20Builder /builds/1771/steps/setup_build/logs/run_recipe"
209 ]
210 ],
211 "name": "setup_build",
212 "results": [
213 0,
214 []
215 ],
216 "step_number": 3,
217 "text": [
218 "setup_build",
219 "<br/>running recipe: \"chromium\""
220 ],
221 "times": [
222 5.5,
223 6.6
224 ],
225 "urls": {}
226 }
227 ],
228 "text": [
229 "build",
230 "successful"
231 ],
232 "times": [
233 1.1,
234 2.2
235 ],
236 }
237 return k_example_build_json
238
239 cache = buildbot.BuildCache(self.cache_path)
240 old_fetch_build_json = buildbot.fetch_build_json
241 try:
242 buildbot.fetch_build_json = mock_fetch_build_json
243
244 builder_info = buildbot.latest_builder_info_for_master(cache,
245 'http://build.chromium.org/p/chromium.webkit', k_example_master_json)
246 expected_builder_info = {
247 'chromium.webkit': {
248 'Win Builder': {
249 'state': 'building',
250 'lastUpdateTime': 2.2,
251 'revisions': {
252 'v8': 23117,
253 'chromium': 289623,
254 'nacl': 13611,
255 'blink': 180191
256 }
257 }
258 }
259 }
260 self.assertEqual(builder_info, expected_builder_info)
261 finally:
262 buildbot.fetch_build_json = old_fetch_build_json
263
264 def test_latest_update_time_for_builder(self):
265 k_example_last_build_times = {
266 "times": [
267 10,
268 11
269 ],
270 "steps": [
271 {
272 "times": [
273 20,
274 21
275 ]
276 },
277 {
278 "times": [
279 22
280 ]
281 }
282 ]
283 }
284
285 # Test that we use end time when it's present,
286 time = buildbot.latest_update_time_for_builder(k_example_last_build_times)
287 self.assertEqual(time, 11)
288
289 # And test that we iterate across step start times when it isn't.
290 k_example_last_build_times["times"][1] = None
291 time = buildbot.latest_update_time_for_builder(k_example_last_build_times)
292 self.assertEqual(time, 22)
293
36 294
37 class BuildbotTest(unittest.TestCase): 295 class BuildbotTest(unittest.TestCase):
38 def test_master_name_from_url(self): 296 def test_master_name_from_url(self):
39 tests = [ 297 tests = [
40 ('https://build.chromium.org/p/chromium.mac', 'chromium.mac'), 298 ('https://build.chromium.org/p/chromium.mac', 'chromium.mac'),
41 ('https://build.chromium.org/p/tryserver.blink', 'tryserver.blink') 299 ('https://build.chromium.org/p/tryserver.blink', 'tryserver.blink')
42 ] 300 ]
43 for master_url, master_name in tests: 301 for master_url, master_name in tests:
44 self.assertEquals(buildbot.master_name_from_url(master_url), master_name) 302 self.assertEquals(buildbot.master_name_from_url(master_url), master_name)
45 303
46 def test_build_url(self): 304 def test_build_url(self):
47 url = buildbot.build_url('https://foo.com/p/bar', 'baz', '12') 305 url = buildbot.build_url('https://foo.com/p/bar', 'baz', '12')
48 self.assertEquals(url, 'https://foo.com/p/bar/builders/baz/builds/12') 306 self.assertEquals(url, 'https://foo.com/p/bar/builders/baz/builds/12')
49 307
50 def test_cache_key_for_build(self): 308 def test_cache_key_for_build(self):
51 key = buildbot.cache_key_for_build('master', 'builder', 10) 309 key = buildbot.cache_key_for_build('master', 'builder', 10)
52 self.assertEquals(key, 'master/builder/10.json') 310 self.assertEquals(key, 'master/builder/10.json')
53 311
54 def test_is_in_progress(self): 312 def test_is_in_progress(self):
55 self.assertEqual(buildbot.is_in_progress({'results': None}), True) 313 self.assertEqual(buildbot.is_in_progress({'results': None}), True)
56 self.assertEqual(buildbot.is_in_progress({'results': 2}), False) 314 self.assertEqual(buildbot.is_in_progress({'results': 2}), False)
OLDNEW
« infra/tools/builder_alerts/buildbot.py ('K') | « infra/tools/builder_alerts/buildbot.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698