Skip to content

Commit

Permalink
feat: ta processor handles placeholder storage
Browse files Browse the repository at this point in the history
we want to be able to specify an upload that was not able to find a file
so we can make a comment on the PR letting the user know that a file
was not found.

this upload is represented using the "placeholder" storage path
  • Loading branch information
joseph-sentry committed Dec 27, 2024
1 parent c650bbe commit 503a6c6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 7 deletions.
25 changes: 18 additions & 7 deletions services/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,24 @@ def messagify_flake(

def specific_error_message(upload_error: UploadError) -> str:
title = f"### :x: {upload_error.error_code}"
description = "\n".join(
[
f"Upload processing failed due to {upload_error.error_code.lower()}. Please review the parser error message:",
f"`{upload_error.error_params['error_message']}`",
"For more help, visit our [troubleshooting guide](https://docs.codecov.com/docs/test-analytics#troubleshooting).",
]
)
if upload_error.error_code == "Unsupported file format":
description = "\n".join(
[
"Upload processing failed due to unsupported file format. Please review the parser error message:",
f"`{upload_error.error_params['error_message']}`",
"For more help, visit our [troubleshooting guide](https://docs.codecov.com/docs/test-analytics#troubleshooting).",
]
)
elif upload_error.error_code == "File not found":
description = "\n".join(
[
"No result to display due to the CLI not being able to find the file.",
"Please ensure the file contains `junit` in the name and automated file search is enabled,",
"or the desired file specified by the `file` and `search_dir` arguments of the CLI.",
]
)
else:
raise ValueError("Unrecognized error code")
message = [
title,
make_quoted(description),
Expand Down
11 changes: 11 additions & 0 deletions tasks/ta_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def process_individual_upload(
# don't need to process again because the intermediate result should already be in redis
return False

if upload.storage_path == "placeholder":
upload.state = "v2_processed"
new_upload_error = UploadError(
upload_id=upload.id,
error_code="File not found",
error_params={},
)
db_session.add(new_upload_error)
db_session.commit()
return False

payload_bytes = archive_service.read_file(upload.storage_path)

try:
Expand Down
64 changes: 64 additions & 0 deletions tasks/tests/unit/test_ta_finisher_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,67 @@ def test_test_analytics_regular_comment_with_error(

rollups = dbsession.query(DailyTestRollup).all()
assert len(rollups) == 1


def test_ta_file_not_found(
dbsession,
mocker,
mock_storage,
celery_app,
mock_repo_provider_service,
mock_pull_request_information,
generate_junit,
):
mocker.patch.object(TAProcessorTask, "app", celery_app)
mocker.patch.object(TAFinisherTask, "app", celery_app)

commit = CommitFactory.create()

upload = generate_junit(raw="a", commit=commit)
upload.storage_path = "placeholder"
dbsession.flush()

argument = {"url": "placeholder", "upload_id": upload.id_}
result = TAProcessorTask().run_impl(
dbsession,
repoid=upload.report.commit.repoid,
commitid=upload.report.commit.commitid,
commit_yaml={"codecov": {"max_report_age": False}},
argument=argument,
)
assert result is False

result = TAFinisherTask().run_impl(
dbsession,
chord_result=[result],
repoid=upload.report.commit.repoid,
commitid=upload.report.commit.commitid,
commit_yaml={"codecov": {"max_report_age": False}},
)

assert result["notify_attempted"] is True
assert result["notify_succeeded"] is True
assert result["queue_notify"] is True

short_form_service_name = services_short_dict.get(
upload.report.commit.repository.owner.service
)

mock_repo_provider_service.edit_comment.assert_called_once()
mock_repo_provider_service.edit_comment.assert_called_once_with(
mock_pull_request_information.database_pull.pullid,
mock_pull_request_information.database_pull.commentid,
"""### :x: File not found
> No result to display due to the CLI not being able to find the file.
> Please ensure the file contains `junit` in the name and automated file search is enabled,
> or the desired file specified by the `file` and `search_dir` arguments of the CLI.
""",
)

tests = dbsession.query(Test).all()
assert len(tests) == 0
test_instances = dbsession.query(TestInstance).all()
assert len(test_instances) == 0
rollups = dbsession.query(DailyTestRollup).all()
assert len(rollups) == 0

0 comments on commit 503a6c6

Please sign in to comment.