Skip to content

Commit

Permalink
fix: make notify error opt in using codecov.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-sentry committed Jul 31, 2024
1 parent a108313 commit caea890
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
53 changes: 44 additions & 9 deletions tasks/tests/unit/test_upload_finisher_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,24 @@ def test_should_call_notifications_manual_trigger_off(self, dbsession):
== ShouldCallNotifResult.NOTIFY
)

def test_should_call_notifications_no_successful_reports(self, dbsession):
commit_yaml = {"codecov": {"max_report_age": "1y ago"}}
@pytest.mark.parametrize(
"fail_on_any_processing_error,result",
[
(True, ShouldCallNotifResult.NOTIFY_ERROR),
(False, ShouldCallNotifResult.DO_NOT_NOTIFY),
],
)
def test_should_call_notifications_no_successful_reports(
self, dbsession, fail_on_any_processing_error, result
):
commit_yaml = {
"codecov": {
"max_report_age": "1y ago",
"notify": {
"fail_on_any_processing_error": fail_on_any_processing_error
},
}
}
commit = CommitFactory.create(
message="dsidsahdsahdsa",
commitid="abf6d4df662c47e32460020ab14abf9303581429",
Expand All @@ -308,7 +324,7 @@ def test_should_call_notifications_no_successful_reports(self, dbsession):
UploadFinisherTask().should_call_notifications(
commit, commit_yaml, processing_results, None
)
== ShouldCallNotifResult.NOTIFY_ERROR
== result
)

def test_should_call_notifications_not_enough_builds(self, dbsession, mocker):
Expand Down Expand Up @@ -532,13 +548,24 @@ def test_finish_reports_processing_call_clean_labels(self, dbsession, mocker):
)
assert mocked_app.send_task.call_count == 0

def test_finish_reports_processing_no_notification(self, dbsession, mocker):
commit_yaml = {}
@pytest.mark.parametrize(
"fail_on_any_processing_error",
[True, False],
)
def test_finish_reports_processing_no_notification(
self, dbsession, mocker, fail_on_any_processing_error
):
commit_yaml = {
"codecov": {
"notify": {"fail_on_any_processing_error": fail_on_any_processing_error}
}
}
mocked_app = mocker.patch.object(
UploadFinisherTask,
"app",
tasks={
"app.tasks.notify.NotifyErrorTask": mocker.MagicMock(),
"app.tasks.notify.Notify": mocker.MagicMock(),
},
)
commit = CommitFactory.create(
Expand All @@ -562,10 +589,18 @@ def test_finish_reports_processing_no_notification(self, dbsession, mocker):
checkpoints,
)
assert res == {"notifications_called": False}
assert mocked_app.send_task.call_count == 0
mocked_app.tasks[
"app.tasks.notify.NotifyErrorTask"
].apply_async.assert_called_once()
if fail_on_any_processing_error:
assert mocked_app.send_task.call_count == 0
mocked_app.tasks[
"app.tasks.notify.NotifyErrorTask"
].apply_async.assert_called_once()
mocked_app.tasks["app.tasks.notify.Notify"].apply_async.assert_not_called()
else:
assert mocked_app.send_task.call_count == 0
mocked_app.tasks[
"app.tasks.notify.NotifyErrorTask"
].apply_async.assert_not_called()
mocked_app.tasks["app.tasks.notify.Notify"].apply_async.assert_not_called()

@pytest.mark.django_db(databases={"default"})
def test_upload_finisher_task_calls_save_commit_measurements_task(
Expand Down
20 changes: 14 additions & 6 deletions tasks/upload_finisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,21 @@ def should_call_notifications(
x["successful"] for x in processing_results.get("processings_so_far", [])
]

if len(processing_successses) == 0 or not all(processing_successses):
log.info(
"Not scheduling notify because there is a non-successful processing result",
extra=extra_dict,
)
if read_yaml_field(
commit_yaml,
("codecov", "notify", "fail_on_any_processing_error"),
_else=False,
):
if len(processing_successses) == 0 or not all(processing_successses):
log.info(
"Not scheduling notify because there is a non-successful processing result",
extra=extra_dict,
)

return ShouldCallNotifResult.NOTIFY_ERROR
return ShouldCallNotifResult.NOTIFY_ERROR
else:
if not any(processing_successses):
return ShouldCallNotifResult.DO_NOT_NOTIFY

return ShouldCallNotifResult.NOTIFY

Expand Down

0 comments on commit caea890

Please sign in to comment.