From a65c4ed4567b5eca250bdfd8f8a9a35ca5ca280e Mon Sep 17 00:00:00 2001
From: Antoine Lambert <anlambert@softwareheritage.org>
Date: Thu, 26 Jan 2023 14:06:45 +0100
Subject: [PATCH] celery_backend/config: Fix missing comma in setup_log_handler

Because of that missing comma, an exception was raised (tuple object is
not callable) but it was caught and displayed by the _print_errors decorator
so tests could not detect it.

As a consequence, the logging configuration of celery workers was broken.

Add a test to check if an exception was raised by the setup_log_handler
function to avoid bad surprises when deploying to production or in
docker.
---
 swh/scheduler/celery_backend/config.py | 2 +-
 swh/scheduler/tests/test_config.py     | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/swh/scheduler/celery_backend/config.py b/swh/scheduler/celery_backend/config.py
index eb23f1fd..6404cc7e 100644
--- a/swh/scheduler/celery_backend/config.py
+++ b/swh/scheduler/celery_backend/config.py
@@ -125,7 +125,7 @@ def setup_log_handler(
 
     logging_configure(
         [
-            ("celery", logging.INFO)
+            ("celery", logging.INFO),
             # Silence amqp heartbeat_tick messages
             ("amqp", loglevel),
             # Silence useless "Starting new HTTP connection" messages
diff --git a/swh/scheduler/tests/test_config.py b/swh/scheduler/tests/test_config.py
index 313a19b7..46b89a91 100644
--- a/swh/scheduler/tests/test_config.py
+++ b/swh/scheduler/tests/test_config.py
@@ -10,6 +10,7 @@ from swh.scheduler.celery_backend.config import (
     app,
     get_available_slots,
     route_for_task,
+    setup_log_handler,
 )
 
 
@@ -63,3 +64,11 @@ def test_get_available_slots(mocker):
     actual_num = get_available_slots(app, "anything", max_length)
     assert actual_num == max_length - queue_length
     assert mock.called
+
+
+def test_setup_log_handler(capsys):
+    setup_log_handler()
+    # exceptions are caught and displayed by the setup_log_handler function
+    # as celery eats tracebacks in signal handler, check no traceback was
+    # displayed then
+    assert "Traceback" not in capsys.readouterr().err
-- 
GitLab