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

Side by Side Diff: infra_libs/event_mon/test/monitoring_test.py

Issue 2108803004: Add support for build category in BuildEvent (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Addressed comments Created 4 years, 5 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_libs/event_mon/monitoring.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 # -*- encoding:utf-8 -*- 1 # -*- encoding:utf-8 -*-
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import unittest 6 import unittest
7 7
8 from infra_libs import event_mon 8 from infra_libs import event_mon
9 from infra_libs.event_mon import config, router 9 from infra_libs.event_mon import config, router
10 from infra_libs.event_mon import monitoring 10 from infra_libs.event_mon import monitoring
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 # Check that source_extension deserializes to the right thing. 321 # Check that source_extension deserializes to the right thing.
322 event = ChromeInfraEvent.FromString(log_event.source_extension) 322 event = ChromeInfraEvent.FromString(log_event.source_extension)
323 self.assertTrue(event.HasField('build_event')) 323 self.assertTrue(event.HasField('build_event'))
324 self.assertEquals(event.build_event.bbucket_id, 123) 324 self.assertEquals(event.build_event.bbucket_id, 123)
325 325
326 # Try invalid value. This should not throw any exceptions. 326 # Try invalid value. This should not throw any exceptions.
327 log_event = monitoring.get_build_event( 327 log_event = monitoring.get_build_event(
328 'BUILD', 'bot.host.name', 'build_name', bbucket_id='foo').log_event() 328 'BUILD', 'bot.host.name', 'build_name', bbucket_id='foo').log_event()
329 self.assertIsInstance(log_event, LogRequestLite.LogEventLite) 329 self.assertIsInstance(log_event, LogRequestLite.LogEventLite)
330 330
331 def test_get_build_event_with_category(self):
332 log_event = monitoring.get_build_event(
333 'BUILD', 'bot.host.name', 'build_name',
334 category='git_cl_try').log_event()
335 self.assertIsInstance(log_event, LogRequestLite.LogEventLite)
336
337 # Check that source_extension deserializes to the right thing.
338 event = ChromeInfraEvent.FromString(log_event.source_extension)
339 self.assertTrue(event.HasField('build_event'))
340 self.assertEquals(
341 event.build_event.category, BuildEvent.CATEGORY_GIT_CL_TRY)
342
343 # Try unknown value. Should produce CATEGORY_UNKNOWN.
344 log_event = monitoring.get_build_event(
345 'BUILD', 'bot.host.name', 'build_name', category='foobar').log_event()
346 self.assertIsInstance(log_event, LogRequestLite.LogEventLite)
347 event = ChromeInfraEvent.FromString(log_event.source_extension)
348 self.assertTrue(event.HasField('build_event'))
349 self.assertEquals(
350 event.build_event.category, BuildEvent.CATEGORY_UNKNOWN)
351
352 # Try empty value. Should not set category.
353 log_event = monitoring.get_build_event(
354 'BUILD', 'bot.host.name', 'build_name', category='').log_event()
355 self.assertIsInstance(log_event, LogRequestLite.LogEventLite)
356 event = ChromeInfraEvent.FromString(log_event.source_extension)
357 self.assertTrue(event.HasField('build_event'))
358 self.assertFalse(event.build_event.HasField('category'))
359
331 def test_get_build_event_invalid_type(self): 360 def test_get_build_event_invalid_type(self):
332 # An invalid type is a critical error. 361 # An invalid type is a critical error.
333 log_event = monitoring.get_build_event('INVALID_TYPE', 362 log_event = monitoring.get_build_event('INVALID_TYPE',
334 'bot.host.name', 363 'bot.host.name',
335 'build_name').log_event() 364 'build_name').log_event()
336 self.assertIsNone(log_event) 365 self.assertIsNone(log_event)
337 366
338 def test_get_build_event_invalid_build_name(self): 367 def test_get_build_event_invalid_build_name(self):
339 # an invalid builder name is not a critical error. 368 # an invalid builder name is not a critical error.
340 hostname = 'bot.host.name' 369 hostname = 'bot.host.name'
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 'BUILD', 1258 'BUILD',
1230 'bot2.host.name', 1259 'bot2.host.name',
1231 'build_name2', 1260 'build_name2',
1232 build_number=1, 1261 build_number=1,
1233 build_scheduling_time=123456789, 1262 build_scheduling_time=123456789,
1234 result='FAILURE', 1263 result='FAILURE',
1235 timestamp_kind='POINT', 1264 timestamp_kind='POINT',
1236 event_timestamp=None), 1265 event_timestamp=None),
1237 ] 1266 ]
1238 self.assertTrue(monitoring.send_events(events)) 1267 self.assertTrue(monitoring.send_events(events))
OLDNEW
« no previous file with comments | « infra_libs/event_mon/monitoring.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698