def test_kill_mongo_procs(self): """ Test kill_mongo_procs """ local = LocalHost() local.kill_remote_procs = MagicMock(name="kill_remote_procs") local.kill_remote_procs.return_value = True self.assertTrue(local.kill_mongo_procs()) local.kill_remote_procs.assert_called_once_with("mongo", 9, max_time_ms=30000)
def test_kill_remote_procs(self): """ Test kill_remote_procs """ local = LocalHost() local.run = MagicMock(name="run") local.run.return_value = False self.assertTrue(local.kill_remote_procs("mongo")) calls = [ call(["pkill", "-9", "mongo"], quiet=True), call(["pgrep", "mongo"], quiet=True) ] local.run.assert_has_calls(calls) with patch( "dsi.common.host_utils.create_timer") as mock_create_watchdog: local.run = MagicMock(name="run") local.run.return_value = False local.kill_remote_procs("mongo", max_time_ms=None) mock_create_watchdog.assert_called_once_with(ANY, None) with patch( "dsi.common.host_utils.create_timer") as mock_create_watchdog: local.run = MagicMock(name="run") local.run.return_value = False local.kill_remote_procs("mongo", max_time_ms=0, delay_ms=99) mock_create_watchdog.assert_called_once_with(ANY, 99) with patch( "dsi.common.host_utils.create_timer") as mock_create_watchdog: local = LocalHost() local.run = MagicMock(name="run") local.run.return_value = True mock_is_timed_out = MagicMock(name="is_timed_out") mock_create_watchdog.return_value = mock_is_timed_out mock_is_timed_out.side_effect = [False, True] self.assertFalse(local.kill_remote_procs("mongo", delay_ms=1)) local = LocalHost() local.run = MagicMock(name="run") local.run.side_effect = [False, True, False, False] self.assertTrue( local.kill_remote_procs("mongo", signal_number=15, delay_ms=1)) calls = [ call(["pkill", "-15", "mongo"], quiet=True), call(["pgrep", "mongo"], quiet=True), call(["pkill", "-15", "mongo"], quiet=True), call(["pgrep", "mongo"], quiet=True), ] local.run.assert_has_calls(calls)