Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply notify task after lock is released #265

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions tasks/test_results_finisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
Replacement(["\r"], "", EscapeEnum.REPLACE),
Replacement(["\n"], "<br>", EscapeEnum.REPLACE),
]
QUEUE_NOTIFY_KEY = "queue_notify"


class TestResultsFinisherTask(BaseCodecovTask, name=test_results_finisher_task_name):
Expand Down Expand Up @@ -73,14 +74,26 @@ def run_impl(
LockType.NOTIFICATION,
retry_num=self.request.retries,
):
return self.process_impl_within_lock(
finisher_result = self.process_impl_within_lock(
db_session=db_session,
repoid=repoid,
commitid=commitid,
commit_yaml=commit_yaml,
previous_result=chord_result,
**kwargs,
)
if finisher_result[QUEUE_NOTIFY_KEY]:
self.app.tasks[notify_task_name].apply_async(
args=None,
kwargs=dict(
repoid=repoid,
commitid=commitid,
current_yaml=commit_yaml.to_dict(),
),
)

return finisher_result

except LockRetry as retry:
self.retry(max_retries=5, countdown=retry.countdown)

Expand Down Expand Up @@ -115,7 +128,11 @@ def process_impl_within_lock(
"test_results.finisher",
tags={"status": "failure", "reason": "no_successful_processing"},
)
return {"notify_attempted": False, "notify_succeeded": False}
return {
"notify_attempted": False,
"notify_succeeded": False,
QUEUE_NOTIFY_KEY: False,
}

commit_report = commit.commit_report(ReportType.TEST_RESULTS)
with metrics.timing("test_results.finisher.fetch_latest_test_instances"):
Expand Down Expand Up @@ -185,7 +202,11 @@ def process_impl_within_lock(
repoid=repoid, commitid=commitid, current_yaml=commit_yaml.to_dict()
),
)
return {"notify_attempted": False, "notify_succeeded": False}
return {
"notify_attempted": False,
"notify_succeeded": False,
QUEUE_NOTIFY_KEY: True,
}

metrics.incr(
"test_results.finisher",
Expand Down Expand Up @@ -218,7 +239,11 @@ def process_impl_within_lock(
"test_results.finisher.test_result_notifier",
tags={"status": success, "reason": reason},
)
return {"notify_attempted": True, "notify_succeeded": success}
return {
"notify_attempted": True,
"notify_succeeded": success,
QUEUE_NOTIFY_KEY: False,
}

def check_if_no_success(self, previous_result):
return all(
Expand Down
32 changes: 26 additions & 6 deletions tasks/tests/unit/test_test_results_finisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from database.tests.factories import CommitFactory, PullFactory, UploadFactory
from services.repository import EnrichedPull
from services.test_results import generate_test_id
from tasks.test_results_finisher import TestResultsFinisherTask
from tasks.test_results_finisher import QUEUE_NOTIFY_KEY, TestResultsFinisherTask

here = Path(__file__)

Expand Down Expand Up @@ -220,7 +220,11 @@ def test_upload_finisher_task_call(
commit_yaml={"codecov": {"max_report_age": False}},
)

expected_result = {"notify_attempted": True, "notify_succeeded": True}
expected_result = {
"notify_attempted": True,
"notify_succeeded": True,
QUEUE_NOTIFY_KEY: False,
}

assert expected_result == result
mock_repo_provider_comments.post_comment.assert_called_with(
Expand Down Expand Up @@ -278,7 +282,11 @@ def test_upload_finisher_task_call_no_failures(
commit_yaml={"codecov": {"max_report_age": False}},
)

expected_result = {"notify_attempted": False, "notify_succeeded": False}
expected_result = {
"notify_attempted": False,
"notify_succeeded": False,
QUEUE_NOTIFY_KEY: True,
}
test_results_mock_app.tasks[
"app.tasks.notify.Notify"
].apply_async.assert_called_with(
Expand Down Expand Up @@ -336,7 +344,11 @@ def test_upload_finisher_task_call_no_success(
commit_yaml={"codecov": {"max_report_age": False}},
)

expected_result = {"notify_attempted": False, "notify_succeeded": False}
expected_result = {
"notify_attempted": False,
"notify_succeeded": False,
QUEUE_NOTIFY_KEY: False,
}

assert expected_result == result

Expand Down Expand Up @@ -380,7 +392,11 @@ def test_upload_finisher_task_call_existing_comment(
commit_yaml={"codecov": {"max_report_age": False}},
)

expected_result = {"notify_attempted": True, "notify_succeeded": True}
expected_result = {
"notify_attempted": True,
"notify_succeeded": True,
QUEUE_NOTIFY_KEY: False,
}

mock_repo_provider_comments.edit_comment.assert_called_with(
pull.pullid,
Expand Down Expand Up @@ -419,7 +435,11 @@ def test_upload_finisher_task_call_comment_fails(
commit_yaml={"codecov": {"max_report_age": False}},
)

expected_result = {"notify_attempted": True, "notify_succeeded": False}
expected_result = {
"notify_attempted": True,
"notify_succeeded": False,
QUEUE_NOTIFY_KEY: False,
}

assert expected_result == result

Expand Down
Loading