From f894fa13816175f8a42da43d7e4e8036789613a3 Mon Sep 17 00:00:00 2001 From: Gregory Mierzwinski Date: Wed, 15 Apr 2026 16:42:12 -0400 Subject: [PATCH] Bug 2029999 - Handle case when test is empty for perfalert emails. --- tests/perf/test_email.py | 38 +++++++++++++++++++++++++++++++++++++- treeherder/perf/email.py | 12 +++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/tests/perf/test_email.py b/tests/perf/test_email.py index 2d273df9b65..ef24a2eaf72 100644 --- a/tests/perf/test_email.py +++ b/tests/perf/test_email.py @@ -1,6 +1,10 @@ import pytest -from treeherder.perf.email import DeletionNotificationWriter, DeletionReportContent +from treeherder.perf.email import ( + AlertNotificationWriter, + DeletionNotificationWriter, + DeletionReportContent, +) class TestDeletionReportContent: @@ -53,3 +57,35 @@ def __prepare_expected_content(test_perf_signature): ) ) return expected_content + + +class TestAlertNotificationWriter: + def test_subject_and_content_use_suite_when_test_field_is_empty( + self, test_perf_alert, test_perf_alert_summary + ): + test_perf_alert.series_signature.test = "" + test_perf_alert.series_signature.save() + + writer = AlertNotificationWriter() + email = writer.prepare_new_email( + "test@example.com", test_perf_alert, test_perf_alert_summary + ) + + suite = test_perf_alert.series_signature.suite + assert suite in email["subject"] + assert suite in email["content"] + + def test_subject_and_content_use_suite_dot_test_when_test_field_is_set( + self, test_perf_alert, test_perf_alert_summary + ): + suite = test_perf_alert.series_signature.suite + test = test_perf_alert.series_signature.test + expected_test_name = f"{suite}.{test}" + + writer = AlertNotificationWriter() + email = writer.prepare_new_email( + "test@example.com", test_perf_alert, test_perf_alert_summary + ) + + assert expected_test_name in email["subject"] + assert expected_test_name in email["content"] diff --git a/treeherder/perf/email.py b/treeherder/perf/email.py index 9eb7a2ac9c4..dbe0f9ace89 100644 --- a/treeherder/perf/email.py +++ b/treeherder/perf/email.py @@ -321,15 +321,21 @@ def prepare_new_email( self, email: str, alert: PerformanceAlert, alert_summary: PerformanceAlertSummary ) -> dict: self._write_address(email) - self._write_subject(alert.series_signature.test) - self._write_content(alert.series_signature.test, str(alert_summary.id)) + + if not alert.series_signature.test: + test_name = alert.series_signature.suite + else: + test_name = f"{alert.series_signature.suite}.{alert.series_signature.test}" + + self._write_subject(test_name) + self._write_content(test_name, str(alert_summary.id)) return self.email def _write_address(self, email: str): self._email.address = email def _write_subject(self, test: str): - self._email.subject = f"Alert: Test {test} detected a performance change" + self._email.subject = f"Alert: Detected a performance change to {test} " def _write_content(self, test: str, alert_summary_id: str): content = AlertNotificationContent()