Merge pull request #2082 from jiegec/develop

fix: fix unit testing on macOS
pull/2088/head
Nicolas Hennion 2022-07-09 13:45:16 +02:00 committed by GitHub
commit 3e82b79c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View File

@ -23,12 +23,13 @@ def processes_to_programs(processes):
# Create a new entry in the dict (new program) # Create a new entry in the dict (new program)
programs_dict[p[key]] = { programs_dict[p[key]] = {
'time_since_update': p['time_since_update'], 'time_since_update': p['time_since_update'],
'num_threads': p['num_threads'], # some values can be None, e.g. macOS system processes
'cpu_percent': p['cpu_percent'], 'num_threads': p['num_threads'] or 0,
'memory_percent': p['memory_percent'], 'cpu_percent': p['cpu_percent'] or 0,
'cpu_times': p['cpu_times'], 'memory_percent': p['memory_percent'] or 0,
'memory_info': p['memory_info'], 'cpu_times': p['cpu_times'] or (),
'io_counters': p['io_counters'], 'memory_info': p['memory_info'] or (),
'io_counters': p['io_counters'] or (),
'childrens': [p['pid']], 'childrens': [p['pid']],
# Others keys are not used # Others keys are not used
# but should be set to be compliant with the existing process_list # but should be set to be compliant with the existing process_list
@ -41,11 +42,13 @@ def processes_to_programs(processes):
} }
else: else:
# Update a existing entry in the dict (existing program) # Update a existing entry in the dict (existing program)
programs_dict[p[key]]['num_threads'] += p['num_threads'] # some values can be None, e.g. macOS system processes
programs_dict[p[key]]['cpu_percent'] += p['cpu_percent'] programs_dict[p[key]]['num_threads'] += p['num_threads'] or 0
programs_dict[p[key]]['memory_percent'] += p['memory_percent'] programs_dict[p[key]]['cpu_percent'] += p['cpu_percent'] or 0
programs_dict[p[key]]['cpu_times'] += p['cpu_times'] programs_dict[p[key]]['memory_percent'] += p['memory_percent'] or 0
programs_dict[p[key]]['memory_info'] += p['memory_info'] programs_dict[p[key]]['cpu_times'] += p['cpu_times'] or ()
programs_dict[p[key]]['memory_info'] += p['memory_info'] or ()
programs_dict[p[key]]['io_counters'] += p['io_counters'] programs_dict[p[key]]['io_counters'] += p['io_counters']
programs_dict[p[key]]['childrens'].append(p['pid']) programs_dict[p[key]]['childrens'].append(p['pid'])
# If all the subprocess has the same value, display it # If all the subprocess has the same value, display it

View File

@ -277,7 +277,7 @@ class TestGlances(unittest.TestCase):
def test_017_programs(self): def test_017_programs(self):
"""Check Programs function (it's not a plugin).""" """Check Programs function (it's not a plugin)."""
# stats_to_check = [ ] # stats_to_check = [ ]
print('INFO: [TEST_010] Check PROGRAM stats') print('INFO: [TEST_017] Check PROGRAM stats')
stats_grab = processes_to_programs(stats.get_plugin('processlist').get_raw()) stats_grab = processes_to_programs(stats.get_plugin('processlist').get_raw())
self.assertTrue(type(stats_grab) is list, msg='Programs stats is not a list') self.assertTrue(type(stats_grab) is list, msg='Programs stats is not a list')
print('INFO: PROGRAM list stats: %s items in the list' % len(stats_grab)) print('INFO: PROGRAM list stats: %s items in the list' % len(stats_grab))