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

Side by Side Diff: infra_libs/ts_mon/test/interface_test.py

Issue 1296863003: Reduce the number of MetricsData protos to put in each request. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Fix the test Created 5 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_libs/ts_mon/interface.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 functools 5 import functools
6 import threading 6 import threading
7 import time 7 import time
8 import unittest 8 import unittest
9 9
10 import mock 10 import mock
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 def test_flush_raises(self): 88 def test_flush_raises(self):
89 self.assertIsNone(interface.state.global_monitor) 89 self.assertIsNone(interface.state.global_monitor)
90 with self.assertRaises(errors.MonitoringNoConfiguredMonitorError): 90 with self.assertRaises(errors.MonitoringNoConfiguredMonitorError):
91 interface.flush() 91 interface.flush()
92 92
93 def test_flush_many(self): 93 def test_flush_many(self):
94 interface.state.global_monitor = stubs.MockMonitor() 94 interface.state.global_monitor = stubs.MockMonitor()
95 95
96 # pylint: disable=unused-argument 96 # pylint: disable=unused-argument
97 def serialize_to(pb, default_target=None, loop_action=None): 97 def serialize_to(pb, default_target=None, loop_action=None):
98 for _ in xrange(5001): 98 for _ in xrange(1001):
99 loop_action(pb) 99 loop_action(pb)
100 pb.data.add().name = 'foo' 100 pb.data.add().name = 'foo'
101 101
102 # We can't use the mock's call_args_list here because the same object is 102 # We can't use the mock's call_args_list here because the same object is
103 # reused as the argument to both calls and cleared inbetween. 103 # reused as the argument to both calls and cleared inbetween.
104 data_lengths = [] 104 data_lengths = []
105 def send(proto): 105 def send(proto):
106 data_lengths.append(len(proto.data)) 106 data_lengths.append(len(proto.data))
107 interface.state.global_monitor.send.side_effect = send 107 interface.state.global_monitor.send.side_effect = send
108 108
109 fake_metric = mock.Mock() 109 fake_metric = mock.Mock()
110 fake_metric.serialize_to = mock.Mock(side_effect=serialize_to) 110 fake_metric.serialize_to = mock.Mock(side_effect=serialize_to)
111 interface.state.metrics.add(fake_metric) 111 interface.state.metrics.add(fake_metric)
112 112
113 interface.flush() 113 interface.flush()
114 self.assertEquals(2, interface.state.global_monitor.send.call_count) 114 self.assertEquals(2, interface.state.global_monitor.send.call_count)
115 self.assertEqual(5000, data_lengths[0]) 115 self.assertEqual(1000, data_lengths[0])
116 self.assertEqual(1, data_lengths[1]) 116 self.assertEqual(1, data_lengths[1])
117 117
118 def test_register_unregister(self): 118 def test_register_unregister(self):
119 fake_metric = mock.Mock() 119 fake_metric = mock.Mock()
120 self.assertEqual(0, len(interface.state.metrics)) 120 self.assertEqual(0, len(interface.state.metrics))
121 interface.register(fake_metric) 121 interface.register(fake_metric)
122 self.assertEqual(1, len(interface.state.metrics)) 122 self.assertEqual(1, len(interface.state.metrics))
123 interface.unregister(fake_metric) 123 interface.unregister(fake_metric)
124 self.assertEqual(0, len(interface.state.metrics)) 124 self.assertEqual(0, len(interface.state.metrics))
125 125
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 def test_sleeps_for_minimum_zero_secs(self): 283 def test_sleeps_for_minimum_zero_secs(self):
284 self.t.start() 284 self.t.start()
285 285
286 # Flush takes 65 seconds. 286 # Flush takes 65 seconds.
287 interface.flush.side_effect = functools.partial(self.increment_time, 65) 287 interface.flush.side_effect = functools.partial(self.increment_time, 65)
288 288
289 self.assertInRange(30, 60, self.stop_event.timeout_wait()) 289 self.assertInRange(30, 60, self.stop_event.timeout_wait())
290 self.assertAlmostEqual(0, self.stop_event.timeout_wait()) 290 self.assertAlmostEqual(0, self.stop_event.timeout_wait())
291 self.assertAlmostEqual(0, self.stop_event.timeout_wait()) 291 self.assertAlmostEqual(0, self.stop_event.timeout_wait())
OLDNEW
« no previous file with comments | « infra_libs/ts_mon/interface.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698