2023-09-12 22:34:54 +02:00
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from zerver.lib.exceptions import ServerNotReadyError
|
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class HealthTest(ZulipTestCase):
|
|
|
|
def test_healthy(self) -> None:
|
|
|
|
# We do not actually use rabbitmq in tests, so this fails
|
|
|
|
# unless it's mocked out.
|
|
|
|
with mock.patch("zerver.views.health.check_rabbitmq"):
|
|
|
|
result = self.client_get("/health")
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
def test_database_failure(self) -> None:
|
2024-07-12 02:30:32 +02:00
|
|
|
with (
|
|
|
|
mock.patch(
|
|
|
|
"zerver.views.health.check_database",
|
|
|
|
side_effect=ServerNotReadyError("Cannot query postgresql"),
|
|
|
|
),
|
|
|
|
self.assertLogs(level="ERROR") as logs,
|
|
|
|
self.assertRaisesRegex(ServerNotReadyError, r"^Cannot query postgresql$"),
|
2023-10-04 20:45:34 +02:00
|
|
|
):
|
|
|
|
self.client_get("/health")
|
2023-09-12 22:34:54 +02:00
|
|
|
self.assertIn(
|
|
|
|
"zerver.lib.exceptions.ServerNotReadyError: Cannot query postgresql", logs.output[0]
|
|
|
|
)
|