Exemple #1
0
    def test_that_conductor_should_schedule_verification_order_task_if_uploaded_file_path_was_not_existing_before_and_other_requirements_are_met(
            self):
        verification_request = self._prepare_verification_request_with_blender_subtask_definition(
        )

        upload_report = UploadReport(
            path=verification_request.result_package_path,
            verification_request=verification_request,
        )
        upload_report.full_clean()
        upload_report.save()

        with mock.patch('conductor.views.transaction.on_commit'
                        ) as mock_transaction_on_commit:
            response = self.client.post(
                reverse('conductor:report-upload',
                        kwargs={'file_path': self.result_package_path}),
                content_type='application/octet-stream',
            )

            self.assertEqual(response.status_code, 200)
            self.assertEqual(UploadReport.objects.count(), 2)

            mock_transaction_on_commit.assert_not_called()

            verification_request.refresh_from_db()
            self.assertFalse(verification_request.upload_finished)

            response = self.client.post(
                reverse('conductor:report-upload',
                        kwargs={'file_path': self.source_package_path}),
                content_type='application/octet-stream',
            )

            self.assertEqual(response.status_code, 200)
            self.assertEqual(UploadReport.objects.count(), 3)

            mock_transaction_on_commit.assert_called_once()

            verification_request.refresh_from_db()
            self.assertTrue(verification_request.upload_finished)
    def test_conductor_should_not_schedule_verification_order_task_if_it_was_already_scheduled_for_given_verification(
            self):
        verification_request = self._prepare_verification_request_with_blender_subtask_definition(
        )

        upload_report = UploadReport(
            path=verification_request.result_package_path,
            verification_request=verification_request,
        )
        upload_report.full_clean()
        upload_report.save()

        with mock.patch('conductor.views.upload_finished.delay') as mock_task:
            response = self.client.post(
                reverse('conductor:report-upload',
                        kwargs={'file_path': self.source_package_path}),
                content_type='application/octet-stream',
            )

            self.assertEqual(response.status_code, 200)
            self.assertEqual(UploadReport.objects.count(), 2)

            mock_task.assert_called_once_with(
                self.compute_task_def['subtask_id'])

            verification_request.refresh_from_db()
            self.assertTrue(verification_request.upload_finished)

            response = self.client.post(
                reverse('conductor:report-upload',
                        kwargs={'file_path': self.source_package_path}),
                content_type='application/octet-stream',
            )

            self.assertEqual(response.status_code, 200)
            self.assertEqual(UploadReport.objects.count(), 3)
            self.assertEqual(mock_task.call_count, 1)
Exemple #3
0
    def test_blender_verification_request_task_should_schedule_upload_finished_task_if_all_related_upload_requests_have_reports(
            self):
        upload_report = UploadReport(path=self.source_package_path, )
        upload_report.full_clean()
        upload_report.save()

        upload_report = UploadReport(path=self.result_package_path, )
        upload_report.full_clean()
        upload_report.save()

        with mock.patch('conductor.tasks.tasks.transaction.on_commit'
                        ) as transaction_on_commit:
            blender_verification_request(
                frames=self.compute_task_def['extra_data']['frames'],
                subtask_id=self.compute_task_def['subtask_id'],
                source_package_path=self.source_package_path,
                result_package_path=self.result_package_path,
                output_format=BlenderSubtaskDefinition.OutputFormat.JPEG.name,  # pylint: disable=no-member
                scene_file=self.compute_task_def['extra_data']['scene_file'],
                verification_deadline=self.
                _get_verification_deadline_as_timestamp(
                    get_current_utc_timestamp(),
                    self.report_computed_task.size,
                ),
                blender_crop_script_parameters=self.
                blender_crop_script_parameters,
            )

        transaction_on_commit.assert_called_once()
Exemple #4
0
def report_upload(_request: HttpRequest, file_path: str) -> HttpResponse:

    log_request_received(logger, file_path, FileTransferToken.Operation.upload)
    # If there's a corresponding VerificationRequest, the load it and link it to UploadReport.
    try:
        verification_request = VerificationRequest.objects.select_for_update(
        ).get(
            Q(source_package_path=file_path)
            | Q(result_package_path=file_path))
    except VerificationRequest.DoesNotExist:
        verification_request = None

    # The app creates a new instance of UploadReport in the database.
    upload_report = UploadReport(
        path=file_path,
        verification_request=verification_request,
    )
    upload_report.full_clean()
    upload_report.save()

    # The app gets the VerificationRequest and checks if both source and result packages have reports.
    if (verification_request is not None
            and verification_request.blender_subtask_definition is not None
            and verification_request.upload_reports.filter(
                path=verification_request.source_package_path).exists()
            and verification_request.upload_reports.filter(
                path=verification_request.result_package_path).exists()
            and verification_request.upload_reports.filter(
                path=file_path).count() == 1):
        assert file_path in [
            verification_request.source_package_path,
            verification_request.result_package_path
        ]

        verification_request.upload_finished = True
        verification_request.full_clean()
        verification_request.save()

        # If all expected files have been uploaded, the app sends upload_finished task to the work queue.
        def call_upload_finished() -> None:
            upload_finished.delay(verification_request.subtask_id)

        transaction.on_commit(
            call_upload_finished,
            using='storage',
        )

        log(logger,
            'All expected files have been uploaded',
            f'Result package path: {verification_request.result_package_path}.'
            f'Source package path: {verification_request.source_package_path}.',
            subtask_id=verification_request.subtask_id)

    # If ResultTransferRequest matching the file exists, report finished upload.
    result_transfer_request = ResultTransferRequest.objects.filter(
        result_package_path=file_path).first()
    if result_transfer_request is not None:
        update_upload_report(
            file_path=file_path,
            result_transfer_request=result_transfer_request,
        )

    return HttpResponse()