Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test case for CPUCollector with 'extended' flag set
  • Loading branch information
Scott Cunningham committed Jan 17, 2017
commit c810a9a74c4d14f36cbe1456acdd5bd8dd40d789
52 changes: 52 additions & 0 deletions src/collectors/cpu/test/testcpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()