예제 #1
0
    def test_schedule__schedule_return_fail_and_transit_success(self):
        for timeout in (True, False):
            process = MockPipelineProcess()
            mock_ss = MockScheduleService(schedule_return=False,
                                          service_timeout=timeout)
            with mock.patch(PIPELINE_PROCESS_GET,
                            mock.MagicMock(return_value=process)):
                with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET,
                                mock.MagicMock(return_value=mock_ss)):
                    process_id = uniqid()

                    schedule.schedule(process_id, mock_ss.id)

                    mock_ss.service_act.schedule.assert_called_with(
                        PARENT_DATA, mock_ss.callback_data)

                    self.assertEqual(mock_ss.schedule_times, 1)

                    schedule.set_schedule_data.assert_called_once_with(
                        mock_ss.id, PARENT_DATA)

                    mock_ss.destroy.assert_not_called()

                    if timeout:
                        signals.service_activity_timeout_monitor_end.send.assert_called_once_with(
                            sender=mock_ss.service_act.__class__,
                            node_id=mock_ss.service_act.id,
                            version=mock_ss.version)
                    else:
                        signals.service_activity_timeout_monitor_end.send.assert_not_called(
                        )

                    Data.objects.write_node_data.assert_called_once_with(
                        mock_ss.service_act, ex_data=None)

                    process.adjust_status.assert_called_once()

                    mock_ss.service_act.schedule_fail.assert_called_once()

                    signals.service_schedule_fail.send.assert_called_with(
                        sender=ScheduleService,
                        activity_shell=mock_ss.service_act,
                        schedule_service=mock_ss,
                        ex_data=None)

                    valve.send.assert_called_once_with(
                        signals,
                        'activity_failed',
                        sender=process.root_pipeline,
                        pipeline_id=process.root_pipeline_id,
                        pipeline_activity_id=mock_ss.service_act.id)

                    # reset mock
                    schedule.set_schedule_data.reset_mock()
                    signals.service_activity_timeout_monitor_end.send.reset_mock(
                    )
                    Data.objects.write_node_data.reset_mock()
                    signals.service_schedule_fail.send.reset_mock()
                    valve.send.reset_mock()
예제 #2
0
    def test_schedule__can_not_get_schedule_parent_data(self):
        mock_ss = MockScheduleService()
        with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET, mock.MagicMock(return_value=mock_ss)):
            with mock.patch(SCHEDULE_GET_SCHEDULE_PARENT_DATA, mock.MagicMock(return_value=None)):
                process_id = uniqid()

                schedule.schedule(process_id, mock_ss.id)

                mock_ss.destroy.assert_not_called()

                mock_ss.service_act.schedule.assert_not_called()

                schedule.delete_parent_data.assert_called_with(mock_ss.id)
예제 #3
0
    def test_schedule_can_not_find_status(self):
        mock_ss = MockScheduleService()
        with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET, mock.MagicMock(return_value=mock_ss)):
            process_id = uniqid()

            schedule.schedule(process_id, mock_ss.id)

            mock_ss.destroy.assert_called_once()

            schedule.delete_parent_data.assert_not_called()

            # reset mock
            mock_ss.destroy.reset_mock()
예제 #4
0
    def test_schedule__schedule_return_success_and_need_next_schedule(self):
        mock_ss = MockScheduleService(schedule_return=True,
                                      result_bit=True)
        with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET, mock.MagicMock(return_value=mock_ss)):
            process_id = uniqid()

            schedule.schedule(process_id, mock_ss.id)

            mock_ss.service_act.schedule.assert_called_once_with(PARENT_DATA, mock_ss.callback_data)

            self.assertEqual(mock_ss.schedule_times, 1)

            schedule.set_schedule_data.assert_called_once_with(mock_ss.id, PARENT_DATA)

            mock_ss.set_next_schedule.assert_called_once()
예제 #5
0
    def test_schedule__schedule_raise_exception_and_transit_success(self):
        for timeout in (True, False):
            e = Exception()
            mock_ss = MockScheduleService(schedule_exception=e, service_timeout=timeout)
            process = MockPipelineProcess()

            with mock.patch(PIPELINE_PROCESS_SELECT_FOR_UPDATE,
                            mock.MagicMock(return_value=MockQuerySet(get_return=process))):
                with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET, mock.MagicMock(return_value=mock_ss)):
                    process_id = uniqid()

                    schedule.schedule(process_id, mock_ss.id)

                    mock_ss.service_act.schedule.assert_called_once_with(PARENT_DATA, mock_ss.callback_data)

                    self.assertEqual(mock_ss.schedule_times, 1)

                    mock_ss.destroy.assert_not_called()

                    if timeout:
                        signals.service_activity_timeout_monitor_end.send.assert_called_once_with(
                            sender=mock_ss.service_act.__class__,
                            node_id=mock_ss.service_act.id,
                            version=mock_ss.version
                        )
                    else:
                        signals.service_activity_timeout_monitor_end.send.assert_not_called()

                    Data.objects.write_node_data.assert_called()

                    process.adjust_status.assert_called_once()

                    mock_ss.service_act.schedule_fail.assert_called_once()

                    signals.service_schedule_fail.send.assert_called()

                    valve.send.assert_called_once_with(signals,
                                                       'activity_failed',
                                                       sender=process.root_pipeline,
                                                       pipeline_id=process.root_pipeline_id,
                                                       pipeline_activity_id=mock_ss.service_act.id,
                                                       subprocess_id_stack=process.subprocess_stack)

                    signals.service_activity_timeout_monitor_end.send.reset_mock()
                    Data.objects.write_node_data.reset_mock()
                    signals.service_schedule_fail.send.reset_mock()
                    valve.send.reset_mock()
예제 #6
0
    def test_schedule__schedule_raise_exception_and_transit_fail(self):
        e = Exception()
        mock_ss = MockScheduleService(schedule_exception=e)
        with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET, mock.MagicMock(return_value=mock_ss)):
            # 3.1.1. transit fail
            with mock.patch(PIPELINE_STATUS_TRANSIT, mock.MagicMock(return_value=MockActionResult(result=False))):
                process_id = uniqid()

                schedule.schedule(process_id, mock_ss.id)

                mock_ss.service_act.schedule.assert_called_once_with(PARENT_DATA, mock_ss.callback_data)

                self.assertEqual(mock_ss.schedule_times, 1)

                mock_ss.destroy.assert_called_once()

                Data.objects.write_node_data.assert_not_called()
예제 #7
0
    def test_schedule__schedule_return_success_and_wait_callback_but_transit_fail(self):
        for timeout in (True, False):
            mock_ss = MockScheduleService(schedule_return=True,
                                          service_timeout=timeout,
                                          wait_callback=True,
                                          result_bit=True)
            with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET, mock.MagicMock(return_value=mock_ss)):
                process_id = uniqid()

                schedule.schedule(process_id, mock_ss.id)

                mock_ss.service_act.schedule.assert_called_once_with(PARENT_DATA, mock_ss.callback_data)

                self.assertEqual(mock_ss.schedule_times, 1)

                mock_ss.destroy.assert_called_once()

                Data.objects.write_node_data.assert_not_called()
예제 #8
0
    def test_schedule__schedule_return_fail_and_transit_fail(self):
        process = MockPipelineProcess()
        mock_ss = MockScheduleService(schedule_return=False)

        with mock.patch(PIPELINE_PROCESS_GET, mock.MagicMock(return_value=process)):
            with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET, mock.MagicMock(return_value=mock_ss)):
                process_id = uniqid()

                schedule.schedule(process_id, mock_ss.id)

                mock_ss.service_act.schedule.assert_called_with(PARENT_DATA, mock_ss.callback_data)

                self.assertEqual(mock_ss.schedule_times, 1)

                schedule.set_schedule_data.assert_called_once_with(mock_ss.id, PARENT_DATA)

                mock_ss.destroy.assert_called_once()

                Data.objects.write_node_data.assert_not_called()
예제 #9
0
def service_schedule(process_id, schedule_id):
    schedule.schedule(process_id, schedule_id)
예제 #10
0
    def test_schedule__schedule_return_success_and_finished(self):
        parent_data_return = 'data'

        for timeout, result_bit, process_alive in itertools.product(
            (True, False), (True, False), (True, False)):
            mock_ss = MockScheduleService(schedule_return=True,
                                          service_timeout=timeout,
                                          schedule_done=True,
                                          result_bit=result_bit)
            mock_context = MockContext()
            mock_status = MockEngineModelStatus(error_ignorable=False)
            mock_top_pipeline_data = MockData()
            process = MockPipelineProcess(
                is_alive=process_alive,
                top_pipeline_data=mock_top_pipeline_data,
                top_pipeline_context=mock_context)
            mock_parent_data = MockData(get_outputs_return=parent_data_return)

            with mock.patch(SCHEDULE_GET_SCHEDULE_PARENT_DATA,
                            mock.MagicMock(return_value=mock_parent_data)):

                with mock.patch(PIPELINE_SCHEDULE_SERVICE_GET,
                                mock.MagicMock(return_value=mock_ss)):

                    with mock.patch(PIPELINE_STATUS_GET,
                                    mock.MagicMock(return_value=mock_status)):

                        with mock.patch(
                                PIPELINE_PROCESS_SELECT_FOR_UPDATE,
                                mock.MagicMock(return_value=MockQuerySet(
                                    get_return=process))):

                            process_id = uniqid()

                            schedule.schedule(process_id, mock_ss.id)

                            mock_ss.service_act.schedule.assert_called_once_with(
                                mock_parent_data, mock_ss.callback_data)

                            self.assertEqual(mock_ss.schedule_times, 1)

                            if timeout:
                                signals.service_activity_timeout_monitor_end.send.assert_called_once_with(
                                    sender=mock_ss.service_act.__class__,
                                    node_id=mock_ss.service_act.id,
                                    version=mock_ss.version)
                            else:
                                signals.service_activity_timeout_monitor_end.send.assert_not_called(
                                )

                            Data.objects.write_node_data.assert_called_once_with(
                                mock_ss.service_act)

                            if not result_bit:
                                self.assertTrue(mock_status.error_ignorable)
                                mock_status.save.assert_called_once()
                            else:
                                self.assertFalse(mock_status.error_ignorable)
                                mock_status.save.assert_not_called()

                            if not process_alive:
                                mock_ss.destroy.assert_called_once()

                                signals.service_activity_timeout_monitor_end.send.reset_mock(
                                )
                                Data.objects.write_node_data.reset_mock()

                                continue
                            else:
                                mock_ss.destroy.assert_not_called()

                            process.top_pipeline.data.update_outputs.assert_called_once_with(
                                parent_data_return)

                            mock_context.extract_output.assert_called_once_with(
                                mock_ss.service_act)

                            process.save.assert_called_once()

                            schedule.delete_parent_data.assert_called_once_with(
                                mock_ss.id)

                            mock_ss.finish.assert_called_once()

                            signals.service_schedule_success.send.assert_called_once_with(
                                sender=ScheduleService,
                                activity_shell=mock_ss.service_act,
                                schedule_service=mock_ss)

                            valve.send.assert_called_once_with(
                                signals,
                                'wake_from_schedule',
                                sender=ScheduleService,
                                process_id=mock_ss.process_id,
                                activity_id=mock_ss.activity_id)

                            # reset mock
                            signals.service_activity_timeout_monitor_end.send.reset_mock(
                            )
                            Data.objects.write_node_data.reset_mock()
                            schedule.delete_parent_data.reset_mock()
                            signals.service_schedule_success.send.reset_mock()
                            valve.send.reset_mock()