Skip to content

Commit

Permalink
Add test case for CPUCollector with 'extended' flag set
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Cunningham committed Jan 17, 2017
1 parent e32ac29 commit c810a9a
Showing 1 changed file with 52 additions and 0 deletions.
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()

0 comments on commit c810a9a

Please sign in to comment.