| OLD | NEW |
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 interface.register(fake_metric) | 49 interface.register(fake_metric) |
| 50 interface.state.store.set('fake', (), None, 123) | 50 interface.state.store.set('fake', (), None, 123) |
| 51 | 51 |
| 52 interface.flush() | 52 interface.flush() |
| 53 interface.state.global_monitor.send.assert_called_once() | 53 interface.state.global_monitor.send.assert_called_once() |
| 54 proto = interface.state.global_monitor.send.call_args[0][0] | 54 proto = interface.state.global_monitor.send.call_args[0][0] |
| 55 self.assertEqual(1, len(proto.data)) | 55 self.assertEqual(1, len(proto.data)) |
| 56 self.assertEqual('foo', proto.data[0].name) | 56 self.assertEqual('foo', proto.data[0].name) |
| 57 | 57 |
| 58 def test_flush_disabled(self): | 58 def test_flush_disabled(self): |
| 59 interface.reset_for_unittest(disable=True) | |
| 60 interface.state.global_monitor = stubs.MockMonitor() | 59 interface.state.global_monitor = stubs.MockMonitor() |
| 61 interface.state.target = stubs.MockTarget() | 60 interface.state.target = stubs.MockTarget() |
| 61 interface.state.flush_enabled_fn = lambda: False |
| 62 interface.flush() | 62 interface.flush() |
| 63 self.assertFalse(interface.state.global_monitor.send.called) | 63 self.assertFalse(interface.state.global_monitor.send.called) |
| 64 | 64 |
| 65 def test_flush_raises(self): | 65 def test_flush_raises(self): |
| 66 self.assertIsNone(interface.state.global_monitor) | 66 self.assertIsNone(interface.state.global_monitor) |
| 67 with self.assertRaises(errors.MonitoringNoConfiguredMonitorError): | 67 with self.assertRaises(errors.MonitoringNoConfiguredMonitorError): |
| 68 interface.flush() | 68 interface.flush() |
| 69 | 69 |
| 70 def test_flush_many(self): | 70 def test_flush_many(self): |
| 71 interface.state.global_monitor = stubs.MockMonitor() | 71 interface.state.global_monitor = stubs.MockMonitor() |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 def test_sleeps_for_minimum_zero_secs(self): | 299 def test_sleeps_for_minimum_zero_secs(self): |
| 300 self.t.start() | 300 self.t.start() |
| 301 | 301 |
| 302 # Flush takes 65 seconds. | 302 # Flush takes 65 seconds. |
| 303 interface.flush.side_effect = functools.partial(self.increment_time, 65) | 303 interface.flush.side_effect = functools.partial(self.increment_time, 65) |
| 304 | 304 |
| 305 self.assertInRange(30, 60, self.stop_event.timeout_wait()) | 305 self.assertInRange(30, 60, self.stop_event.timeout_wait()) |
| 306 self.assertAlmostEqual(0, self.stop_event.timeout_wait()) | 306 self.assertAlmostEqual(0, self.stop_event.timeout_wait()) |
| 307 self.assertAlmostEqual(0, self.stop_event.timeout_wait()) | 307 self.assertAlmostEqual(0, self.stop_event.timeout_wait()) |
| OLD | NEW |