2
2
3
3
import pytest
4
4
from django .apps import apps
5
- from django .conf import settings
6
5
7
6
from health_check .contrib .celery_ping .apps import HealthCheckConfig
8
7
from health_check .contrib .celery_ping .backends import CeleryPingHealthCheck
@@ -20,7 +19,9 @@ class TestCeleryPingHealthCheck:
20
19
def health_check (self ):
21
20
return CeleryPingHealthCheck ()
22
21
23
- def test_check_status_doesnt_add_errors_when_ping_successful (self , health_check ):
22
+ def test_check_status_doesnt_add_errors_when_ping_successful (
23
+ self , health_check , settings
24
+ ):
24
25
celery_worker = "celery@4cc150a7b49b"
25
26
26
27
with patch (
@@ -59,6 +60,7 @@ def test_check_status_reports_errors_if_ping_responses_are_incorrect(
59
60
def test_check_status_adds_errors_when_ping_successfull_but_not_all_defined_queues_have_consumers (
60
61
self ,
61
62
health_check ,
63
+ settings ,
62
64
):
63
65
celery_worker = "celery@4cc150a7b49b"
64
66
queues = list (settings .CELERY_QUEUES )
@@ -123,6 +125,46 @@ def test_check_status_add_error_when_ping_result_failed(
123
125
assert len (health_check .errors ) == 1
124
126
assert "workers unavailable" in health_check .errors [0 ].message .lower ()
125
127
128
+ def test_check_status_reports_errors_if_ping_responses_are_missing (
129
+ self ,
130
+ health_check ,
131
+ settings ,
132
+ ):
133
+ settings .HEALTHCHECK_CELERY_PING_DESTINATION = [
134
+ "celery1@4cc150a7b49b" ,
135
+ "celery2@4cc150a7b49b" ,
136
+ ]
137
+ with patch (
138
+ self .CELERY_APP_CONTROL_PING ,
139
+ return_value = [
140
+ {"celery1@4cc150a7b49b" : CeleryPingHealthCheck .CORRECT_PING_RESPONSE },
141
+ ],
142
+ ):
143
+ health_check .check_status ()
144
+
145
+ assert len (health_check .errors ) == 1
146
+
147
+ def test_check_status_reports_destinations (
148
+ self ,
149
+ health_check ,
150
+ settings ,
151
+ ):
152
+ settings .HEALTHCHECK_CELERY_PING_DESTINATION = [
153
+ "celery1@4cc150a7b49b" ,
154
+ "celery2@4cc150a7b49b" ,
155
+ ]
156
+ with patch (
157
+ self .CELERY_APP_CONTROL_PING ,
158
+ return_value = [
159
+ {"celery1@4cc150a7b49b" : CeleryPingHealthCheck .CORRECT_PING_RESPONSE },
160
+ {"celery2@4cc150a7b49b" : CeleryPingHealthCheck .CORRECT_PING_RESPONSE },
161
+ {"celery3@4cc150a7b49b" : CeleryPingHealthCheck .CORRECT_PING_RESPONSE },
162
+ ],
163
+ ):
164
+ health_check .check_status ()
165
+
166
+ assert len (health_check .errors ) == 1
167
+
126
168
127
169
class TestCeleryPingHealthCheckApps :
128
170
def test_apps (self ):
0 commit comments