def test_top(self): """ See the following issue: https://github.com/saltstack/salt/issues/56942 """ # Limiting to one process because the test suite might be running as # PID 1 under docker and there may only *be* one process running. result = ps.top(num_processes=1, interval=0) assert len(result) == 1
def test_top_zombie_process(self): # Get 3 pids that are currently running on the system pids = psutil.pids()[:3] # Get a process instance for each of the pids processes = [psutil.Process(pid) for pid in pids] # Patch the middle process to raise ZombieProcess when .cpu_times is called def raise_exception(): raise psutil.ZombieProcess(processes[1].pid) processes[1].cpu_times = raise_exception # Make sure psutil.pids only returns the above 3 pids with patch("salt.utils.psutil_compat.pids", return_value=pids): # Make sure we use our process list from above with patch("salt.utils.psutil_compat.Process", side_effect=processes): result = ps.top(num_processes=1, interval=0) assert len(result) == 1