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

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

Issue 1427903002: send_monitoring_event: support for default event and gomastats (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@event-mon-no-default-kind
Patch Set: Rebased Created 5 years, 1 month 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/config.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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 argparse 5 import argparse
6 import os 6 import os
7 import traceback 7 import traceback
8 import unittest 8 import unittest
9 9
10 import infra_libs 10 import infra_libs
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 # so it's sane to test for changes. 45 # so it's sane to test for changes.
46 hostname = 'a' 46 hostname = 'a'
47 service_name = 'b' 47 service_name = 'b'
48 appengine_name = 'c' 48 appengine_name = 'c'
49 49
50 args = ['--event-mon-run-type', 'dry', 50 args = ['--event-mon-run-type', 'dry',
51 '--event-mon-hostname', hostname, 51 '--event-mon-hostname', hostname,
52 '--event-mon-service-name', service_name, 52 '--event-mon-service-name', service_name,
53 '--event-mon-appengine-name', appengine_name] 53 '--event-mon-appengine-name', appengine_name]
54 self._set_up_args(args=args) 54 self._set_up_args(args=args)
55 event = config._cache['default_event'] 55 event = event_mon.get_default_event()
56 self.assertEquals(event.event_source.host_name, hostname) 56 self.assertEquals(event.event_source.host_name, hostname)
57 self.assertEquals(event.event_source.service_name, service_name) 57 self.assertEquals(event.event_source.service_name, service_name)
58 self.assertEquals(event.event_source.appengine_name, appengine_name) 58 self.assertEquals(event.event_source.appengine_name, appengine_name)
59 59
60 def test_run_type_file_good(self): 60 def test_run_type_file_good(self):
61 try: 61 try:
62 with infra_libs.temporary_directory(prefix='config_test-') as tempdir: 62 with infra_libs.temporary_directory(prefix='config_test-') as tempdir:
63 filename = os.path.join(tempdir, 'output.db') 63 filename = os.path.join(tempdir, 'output.db')
64 self._set_up_args(args=['--event-mon-run-type', 'file', 64 self._set_up_args(args=['--event-mon-run-type', 'file',
65 '--event-mon-output-file', filename]) 65 '--event-mon-output-file', filename])
66 self.assertEqual(config._router.output_file, filename) 66 self.assertEqual(config._router.output_file, filename)
67 except Exception: # pragma: no cover 67 except Exception: # pragma: no cover
68 # help for debugging 68 # help for debugging
69 traceback.print_exc() 69 traceback.print_exc()
70 raise 70 raise
71 71
72 # Direct setup_monitoring testing below this line. 72 # Direct setup_monitoring testing below this line.
73 def test_default_event(self): 73 def test_default_event(self):
74 # The protobuf structure is actually an API not an implementation detail 74 # The protobuf structure is actually an API not an implementation detail
75 # so it's sane to test for changes. 75 # so it's sane to test for changes.
76 event_mon.setup_monitoring() 76 event_mon.setup_monitoring()
77 event = config._cache['default_event'] 77 event = event_mon.get_default_event()
78 self.assertTrue(event.event_source.HasField('host_name')) 78 self.assertTrue(event.event_source.HasField('host_name'))
79 self.assertFalse(event.event_source.HasField('service_name')) 79 self.assertFalse(event.event_source.HasField('service_name'))
80 self.assertFalse(event.event_source.HasField('appengine_name')) 80 self.assertFalse(event.event_source.HasField('appengine_name'))
81 81
82 def test_default_event_with_values(self): 82 def test_default_event_with_values(self):
83 # The protobuf structure is actually an API not an implementation detail 83 # The protobuf structure is actually an API not an implementation detail
84 # so it's sane to test for changes. 84 # so it's sane to test for changes.
85 hostname = 'a' 85 hostname = 'a'
86 service_name = 'b' 86 service_name = 'b'
87 appengine_name = 'c' 87 appengine_name = 'c'
88 88
89 event_mon.setup_monitoring( 89 event_mon.setup_monitoring(
90 hostname=hostname, 90 hostname=hostname,
91 service_name=service_name, 91 service_name=service_name,
92 appengine_name=appengine_name 92 appengine_name=appengine_name
93 ) 93 )
94 event = config._cache['default_event'] 94 event = event_mon.get_default_event()
95 self.assertEquals(event.event_source.host_name, hostname) 95 self.assertEquals(event.event_source.host_name, hostname)
96 self.assertEquals(event.event_source.service_name, service_name) 96 self.assertEquals(event.event_source.service_name, service_name)
97 self.assertEquals(event.event_source.appengine_name, appengine_name) 97 self.assertEquals(event.event_source.appengine_name, appengine_name)
98 98
99 def test_set_default_event(self): 99 def test_set_default_event(self):
100 event_mon.setup_monitoring() 100 event_mon.setup_monitoring()
101 orig_event = config._cache['default_event'] 101 orig_event = event_mon.get_default_event()
102 102
103 # Set the new default event to something different from orig_event 103 # Set the new default event to something different from orig_event
104 # to make sure it has changed. 104 # to make sure it has changed.
105 event = chrome_infra_log_pb2.ChromeInfraEvent() 105 event = chrome_infra_log_pb2.ChromeInfraEvent()
106 new_hostname = orig_event.event_source.host_name + '.foo' 106 new_hostname = orig_event.event_source.host_name + '.foo'
107 event.event_source.host_name = new_hostname 107 event.event_source.host_name = new_hostname
108 event_mon.set_default_event(event) 108 event_mon.set_default_event(event)
109 109
110 new_event = config._cache['default_event'] 110 new_event = event_mon.get_default_event()
111 self.assertEquals(new_event.event_source.host_name, new_hostname) 111 self.assertEquals(new_event.event_source.host_name, new_hostname)
112 112
113 def test_set_default_event_bad_type(self): 113 def test_set_default_event_bad_type(self):
114 event_mon.setup_monitoring() 114 event_mon.setup_monitoring()
115 115
116 # bad type 116 # bad type
117 with self.assertRaises(TypeError): 117 with self.assertRaises(TypeError):
118 event_mon.set_default_event({'hostname': 'foo'}) 118 event_mon.set_default_event({'hostname': 'foo'})
119
120 def test_get_default_event(self):
121 event_mon.setup_monitoring()
122 orig_event = config._cache['default_event']
123 self.assertEqual(orig_event, event_mon.get_default_event())
124 self.assertIsNot(orig_event, event_mon.get_default_event())
OLDNEW
« no previous file with comments | « infra_libs/event_mon/config.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698