diff --git a/src/collectors/cpu/test/testcpu.py b/src/collectors/cpu/test/testcpu.py index 3eefd8f41..f44268e3d 100644 --- a/src/collectors/cpu/test/testcpu.py +++ b/src/collectors/cpu/test/testcpu.py @@ -305,6 +305,58 @@ def test_produces_simple_percent(self, publish_mock): }) +class TestCPUCollectorExtended(CollectorTestCase): + + def setUp(self): + self.config = get_collector_config('CPUCollector', { + 'interval': 10, + 'normalize': False, + 'extended': True, + }) + + self.collector = CPUCollector(self.config, None) + + def test_import(self): + self.assertTrue(CPUCollector) + + @patch.object(Collector, 'publish') + def test_produces_simple_and_complex(self, publish_mock): + # similar to above, we need three mock values: two for the simple + # metric (to calculate a delta), plus one more for the standard + # metrics + patch_open = patch('__builtin__.open', Mock(side_effect=[ + StringIO('cpu 100 200 300 400 500 0 0 0 0 0'), + StringIO('cpu 110 220 330 440 550 0 0 0 0 0'), + StringIO('cpu 100 200 300 400 500 0 0 0 0 0'), + ])) + + patch_open.start() + self.collector.collect() + patch_open.stop() + + self.assertPublishedMany(publish_mock, {}) + + patch_open = patch('__builtin__.open', Mock(side_effect=[ + StringIO('cpu 110 220 330 440 550 0 0 0 0 0'), + StringIO('cpu 120 230 340 450 560 0 0 0 0 0'), + StringIO('cpu 110 220 330 440 550 0 0 0 0 0'), + ])) + + patch_open.start() + self.collector.collect() + patch_open.stop() + + # Since the `extended` config option is set, we should see both simple + # percent-only metrics, but also the standard metrics + self.assertPublishedMany(publish_mock, { + 'total.user': 1.0, + 'total.nice': 2.0, + 'total.system': 3.0, + 'total.idle': 4.0, + 'percent': 75.0 + }) + + ########################################################################## if __name__ == "__main__": unittest.main()