Perhaps easiest described as two test cases: > @mock.patch("thinlinc.vsm.loadinfokeeper.subprocess_n_log") > def test_number_of_users_with_no_processes_in_ps_output(self, proc): > # Given > l = loadinfokeeper.LoadInfoKeeper(mock.MagicMock(name="parent")) > proc.side_effect = [(0, " UID\n", "")] > > # When > l.fetch_dynamic_loadinfo() > > # Then > self.assertEqual(l.loadinfo['num_users'], 0) > > > @mock.patch("thinlinc.vsm.loadinfokeeper.subprocess_n_log") > def test_number_of_users_with_single_process_in_ps_output(self, proc): > # Given > l = loadinfokeeper.LoadInfoKeeper(mock.MagicMock(name="parent")) > proc.side_effect = [(0, " UID\n1\n", "")] > > # When > l.fetch_dynamic_loadinfo() > > # Then > self.assertEqual(l.loadinfo['num_users'], 1) Current results: > ====================================================================== > FAIL: test_number_of_users_with_no_processes_in_ps_output (__main__.LoadInfoKeeperTest) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched > return func(*args, **keywargs) > File "test_loadinfokeeper.py", line 66, in test_number_of_users_with_no_processes_in_ps_output > self.assertEqual(l.loadinfo['num_users'], 0) > AssertionError: 2 != 0 > > ====================================================================== > FAIL: test_number_of_users_with_single_process_in_ps_output (__main__.LoadInfoKeeperTest) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/usr/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched > return func(*args, **keywargs) > File "test_loadinfokeeper.py", line 80, in test_number_of_users_with_single_process_in_ps_output > self.assertEqual(l.loadinfo['num_users'], 1) > AssertionError: 3 != 1
Looks to be working very well. I verified that the problem existed on a 4.7.0 server and that it is fixed now with build 5383. The new code is robust and I couldn't find any ways to break things.