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

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: Fix a couple style issues 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
« no previous file with comments | « infra/tools/builder_alerts/buildbot.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
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 8
9 from infra.tools.builder_alerts import buildbot 9 from infra.tools.builder_alerts import buildbot
10 10
(...skipping 15 matching lines...) Expand all
26 cache.set(test_key, test_data) 26 cache.set(test_key, test_data)
27 # Set it a second time to hit the "already there" case. 27 # Set it a second time to hit the "already there" case.
28 cache.set(test_key, test_data) 28 cache.set(test_key, test_data)
29 29
30 self.assertTrue(cache.has(test_key)) 30 self.assertTrue(cache.has(test_key))
31 self.assertEquals(cache.get(test_key), test_data) 31 self.assertEquals(cache.get(test_key), test_data)
32 32
33 self.assertIsNone(cache.get('does_not_exist')) 33 self.assertIsNone(cache.get('does_not_exist'))
34 self.assertIsNotNone(cache.key_age(test_key)) 34 self.assertIsNotNone(cache.key_age(test_key))
35 35
36 def test_latest_builder_info_for_master(self):
37 k_example_master_json = {
38 "builders": {
39 "Win Builder": {
40 "basedir": "Win_Builder",
41 "cachedBuilds": [
42 0,
43 1770,
44 1771
45 ],
46 "category": "2windows",
47 "currentBuilds": [
48 1772
49 ],
50 "pendingBuilds": 7,
51 "slaves": [
52 "build2-m1"
53 ],
54 "state": "building"
55 }
56 }
57 }
58
59 def mock_fetch_build_json(cache, master_url, builder_name, build_number):
60 k_example_build_json = {
61 "blame": [
62 "alexhenrie24@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98",
63 "yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98"
64 ],
65 "builderName": "Win Builder",
66 "currentStep": None,
67 "eta": None,
68 "number": 1771,
69 "properties": [
70 [
71 "build_archive_url",
72 ("gs://chromium-win-archive/chromium.win/"
73 "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/"\
174 "Win%20Builder/builds/1771/steps/steps/logs/preamble")
175 ],
176 [
177 "stdio",
178 ("http://build.chromium.org/p/chromium.win/builders/"\
179 "Win%20Builder/builds/1771/steps/steps/logs/stdio")
180 ]
181 ],
182 "name": "steps",
183 "results": [
184 0,
185 []
186 ],
187 "step_number": 0,
188 "text": [
189 "running steps via annotated script"
190 ],
191 "times": [
192 3.3,
193 4.4
194 ],
195 "urls": {}
196 },
197 {
198 "eta": None,
199 "expectations": [],
200 "hidden": False,
201 "isFinished": True,
202 "isStarted": True,
203 "logs": [
204 [
205 "stdio",
206 ("http://build.chromium.org/p/chromium.win/builders/"\
207 "Win%20Builder/builds/1771/steps/setup_build/logs/stdio")
208 ],
209 [
210 "run_recipe",
211 ("http://build.chromium.org/p/chromium.win/builders/"\
212 "Win%20Builder/builds/1771/steps/setup_build/logs/run_recipe")
213 ]
214 ],
215 "name": "setup_build",
216 "results": [
217 0,
218 []
219 ],
220 "step_number": 3,
221 "text": [
222 "setup_build",
223 "<br/>running recipe: \"chromium\""
224 ],
225 "times": [
226 5.5,
227 6.6
228 ],
229 "urls": {}
230 }
231 ],
232 "text": [
233 "build",
234 "successful"
235 ],
236 "times": [
237 1.1,
238 2.2
239 ],
240 }
241 return k_example_build_json
242
243 cache = buildbot.BuildCache(self.cache_path)
244 old_fetch_build_json = buildbot.fetch_build_json
245 try:
246 buildbot.fetch_build_json = mock_fetch_build_json
247
248 builder_info = buildbot.latest_builder_info_for_master(cache,
249 'http://build.chromium.org/p/chromium.webkit', k_example_master_json)
250 expected_builder_info = {
251 'chromium.webkit': {
252 'Win Builder': {
253 'state': 'building',
254 'lastUpdateTime': 2.2,
255 'revisions': {
256 'v8': 23117,
257 'chromium': 289623,
258 'nacl': 13611,
259 'blink': 180191
260 }
261 }
262 }
263 }
264 self.assertEqual(builder_info, expected_builder_info)
265 finally:
266 buildbot.fetch_build_json = old_fetch_build_json
267
268 def test_latest_update_time_for_builder(self):
269 k_example_last_build_times = {
270 "times": [
271 10,
272 11
273 ],
274 "steps": [
275 {
276 "times": [
277 20,
278 21
279 ]
280 },
281 {
282 "times": [
283 22
284 ]
285 }
286 ]
287 }
288
289 # Test that we use end time when it's present,
290 time = buildbot.latest_update_time_for_builder(k_example_last_build_times)
291 self.assertEqual(time, 11)
292
293 # And test that we iterate across step start times when it isn't.
294 k_example_last_build_times["times"][1] = None
295 time = buildbot.latest_update_time_for_builder(k_example_last_build_times)
296 self.assertEqual(time, 22)
297
36 298
37 class BuildbotTest(unittest.TestCase): 299 class BuildbotTest(unittest.TestCase):
38 def test_master_name_from_url(self): 300 def test_master_name_from_url(self):
39 tests = [ 301 tests = [
40 ('https://build.chromium.org/p/chromium.mac', 'chromium.mac'), 302 ('https://build.chromium.org/p/chromium.mac', 'chromium.mac'),
41 ('https://build.chromium.org/p/tryserver.blink', 'tryserver.blink') 303 ('https://build.chromium.org/p/tryserver.blink', 'tryserver.blink')
42 ] 304 ]
43 for master_url, master_name in tests: 305 for master_url, master_name in tests:
44 self.assertEquals(buildbot.master_name_from_url(master_url), master_name) 306 self.assertEquals(buildbot.master_name_from_url(master_url), master_name)
45 307
46 def test_build_url(self): 308 def test_build_url(self):
47 url = buildbot.build_url('https://foo.com/p/bar', 'baz', '12') 309 url = buildbot.build_url('https://foo.com/p/bar', 'baz', '12')
48 self.assertEquals(url, 'https://foo.com/p/bar/builders/baz/builds/12') 310 self.assertEquals(url, 'https://foo.com/p/bar/builders/baz/builds/12')
49 311
50 def test_cache_key_for_build(self): 312 def test_cache_key_for_build(self):
51 key = buildbot.cache_key_for_build('master', 'builder', 10) 313 key = buildbot.cache_key_for_build('master', 'builder', 10)
52 self.assertEquals(key, 'master/builder/10.json') 314 self.assertEquals(key, 'master/builder/10.json')
53 315
54 def test_is_in_progress(self): 316 def test_is_in_progress(self):
55 self.assertEqual(buildbot.is_in_progress({'results': None}), True) 317 self.assertEqual(buildbot.is_in_progress({'results': None}), True)
56 self.assertEqual(buildbot.is_in_progress({'results': 2}), False) 318 self.assertEqual(buildbot.is_in_progress({'results': 2}), False)
OLDNEW
« no previous file with comments | « infra/tools/builder_alerts/buildbot.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698