def test_024_switchboard_process_loop_calls_do_work_once(
            self, mock_psutil_proc):
        """Process loop calls _do_work at least once."""
        mock_start_event = MagicMock(spec=_MULTIPROCESSING_EVENT)
        mock_stop_event = MagicMock(spec=_MULTIPROCESSING_EVENT)
        mock_terminate_event = MagicMock(spec=_MULTIPROCESSING_EVENT)

        mock_switchboard_process = MagicMock(
            spec=switchboard_process.SwitchboardProcess)
        mock_switchboard_process.device_name = "mock_device"
        mock_switchboard_process.process_name = "mock_process"
        mock_switchboard_process._exception_queue = self.exception_queue
        mock_switchboard_process.logging_queue = MagicMock()
        mock_switchboard_process._start_event = mock_start_event
        mock_switchboard_process._stop_event = mock_stop_event
        mock_switchboard_process._terminate_event = mock_terminate_event

        mock_parent_proc = mock_psutil_proc.return_value
        mock_switchboard_process._pre_run_hook.return_value = True
        mock_terminate_event.is_set.return_value = False
        mock_switchboard_process._do_work.return_value = False

        with mock.patch.object(
                gdm_logger,
                "initialize_child_process_logging") as mock_initialize_logging:
            switchboard_process._process_loop(mock_switchboard_process, 1234)

        mock_initialize_logging.assert_called_once()
        mock_start_event.set.assert_called_once()
        mock_switchboard_process._pre_run_hook.assert_called_once()
        mock_parent_proc.status.assert_called_once()
        mock_terminate_event.is_set.assert_called_once()
        mock_terminate_event.clear.assert_not_called()
        mock_switchboard_process._do_work.assert_called_once()
        mock_stop_event.set.assert_called_once()
    def test_026_switchboard_process_loop_start_event_set_exception(
            self, mock_psutil_proc):
        """Process loop manager in parent process shutdown."""
        mock_start_event = MagicMock(spec=_MULTIPROCESSING_EVENT)
        mock_stop_event = MagicMock(spec=_MULTIPROCESSING_EVENT)
        mock_terminate_event = MagicMock(spec=_MULTIPROCESSING_EVENT)

        mock_switchboard_process = MagicMock(
            spec=switchboard_process.SwitchboardProcess)
        mock_switchboard_process.device_name = "mock_device"
        mock_switchboard_process.process_name = "mock_process"
        mock_switchboard_process._exception_queue = self.exception_queue
        mock_switchboard_process.logging_queue = MagicMock()
        mock_switchboard_process._start_event = mock_start_event
        mock_switchboard_process._stop_event = mock_stop_event
        mock_switchboard_process._terminate_event = mock_terminate_event

        mock_switchboard_process._pre_run_hook.return_value = True
        mock_switchboard_process._do_work.return_value = False
        mock_terminate_event.is_set.return_value = False
        mock_start_event.set.side_effect = IOError("[Errno 32] Broken pipe")

        with mock.patch.object(
                gdm_logger,
                "initialize_child_process_logging") as mock_initialize_logging:
            switchboard_process._process_loop(mock_switchboard_process, 1234)

        mock_initialize_logging.assert_called_once()
        mock_start_event.set.assert_called_once()
        mock_terminate_event.is_set.assert_called_once()
        mock_terminate_event.clear.assert_not_called()
        mock_switchboard_process._do_work.assert_called_once()
        mock_stop_event.set.assert_called_once()
Exemplo n.º 3
0
    def test_switchboard_process_loop(self, mock_psutil_proc):
        """Process loop calls _do_work at least once."""
        logging_queue = multiprocessing_utils.get_context().Queue()
        exception_queue = multiprocessing_utils.get_context().Queue()
        mock_start_event = mock.MagicMock(
            spec=multiprocessing_utils.get_context().Event())
        mock_stop_event = mock.MagicMock(
            spec=multiprocessing_utils.get_context().Event())
        mock_terminate_event = mock.MagicMock(
            spec=multiprocessing_utils.get_context().Event())

        mock_switchboard_process = mock.MagicMock(
            spec=switchboard_process.SwitchboardProcess)
        mock_switchboard_process.device_name = "mock_device"
        mock_switchboard_process.process_name = "mock_process"
        mock_switchboard_process.logging_queue = logging_queue
        mock_switchboard_process._exception_queue = exception_queue
        mock_switchboard_process._start_event = mock_start_event
        mock_switchboard_process._stop_event = mock_stop_event
        mock_switchboard_process._terminate_event = mock_terminate_event

        mock_parent_proc = mock_psutil_proc.return_value
        mock_switchboard_process._pre_run_hook.return_value = True
        mock_terminate_event.is_set.return_value = False
        mock_switchboard_process._do_work.return_value = False

        with mock.patch.object(
                gdm_logger,
                "initialize_child_process_logging") as mock_init_logging:
            switchboard_process._process_loop(mock_switchboard_process, 1234)

        mock_init_logging.assert_called_once()
        mock_start_event.set.assert_called_once()
        mock_switchboard_process._pre_run_hook.assert_called_once()
        mock_parent_proc.status.assert_called_once()
        mock_terminate_event.is_set.assert_called_once()
        mock_terminate_event.clear.assert_not_called()
        mock_switchboard_process._do_work.assert_called_once()
        mock_stop_event.set.assert_called_once()