This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch elizabeth/task-retry
in repository https://gitbox.apache.org/repos/asf/superset.git

commit d0d59774ad1b377c7db6db1937c1f87e8c58754c
Author: Elizabeth Thompson <[email protected]>
AuthorDate: Fri Oct 17 11:53:56 2025 -0700

    test(tasks): Add tests for log_task_failure signal handler
    
    Added unit tests to verify the log_task_failure signal handler:
    - Test logging with sender task provided
    - Test logging when sender is None (fallback to "Unknown")
    
    Both tests verify the correct logging behavior with proper exception info.
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-Authored-By: Claude <[email protected]>
---
 tests/integration_tests/reports/scheduler_tests.py | 49 +++++++++++++++++++++-
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/tests/integration_tests/reports/scheduler_tests.py 
b/tests/integration_tests/reports/scheduler_tests.py
index 93df88379c..38c8547357 100644
--- a/tests/integration_tests/reports/scheduler_tests.py
+++ b/tests/integration_tests/reports/scheduler_tests.py
@@ -16,7 +16,7 @@
 # under the License.
 
 from random import randint
-from unittest.mock import patch
+from unittest.mock import MagicMock, patch
 
 import pytest
 from flask_appbuilder.security.sqla.models import User
@@ -25,7 +25,7 @@ from freezegun.api import FakeDatetime
 
 from superset.extensions import db
 from superset.reports.models import ReportScheduleType
-from superset.tasks.scheduler import execute, scheduler
+from superset.tasks.scheduler import execute, log_task_failure, scheduler
 from tests.integration_tests.reports.utils import insert_report_schedule
 from tests.integration_tests.test_app import app
 
@@ -201,3 +201,48 @@ def test_execute_task_with_command_exception(
 
     db.session.delete(report_schedule)
     db.session.commit()
+
+
+@patch("superset.tasks.scheduler.logger")
+def test_log_task_failure_with_sender(logger_mock):
+    """
+    Test that log_task_failure logs correctly when sender is provided
+    """
+    mock_task = MagicMock()
+    mock_task.name = "test.task.name"
+    mock_exception = Exception("Test error")
+    mock_einfo = MagicMock()
+
+    log_task_failure(
+        sender=mock_task,
+        task_id="test-task-id",
+        exception=mock_exception,
+        einfo=mock_einfo,
+    )
+
+    logger_mock.exception.assert_called_once_with(
+        "Celery task %s failed: %s",
+        "test.task.name",
+        mock_exception,
+        exc_info=mock_einfo,
+    )
+
+
+@patch("superset.tasks.scheduler.logger")
+def test_log_task_failure_without_sender(logger_mock):
+    """
+    Test that log_task_failure logs correctly when sender is None
+    """
+    mock_exception = Exception("Test error")
+    mock_einfo = MagicMock()
+
+    log_task_failure(
+        sender=None,
+        task_id="test-task-id",
+        exception=mock_exception,
+        einfo=mock_einfo,
+    )
+
+    logger_mock.exception.assert_called_once_with(
+        "Celery task %s failed: %s", "Unknown", mock_exception, 
exc_info=mock_einfo
+    )

Reply via email to