This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ES healthchecks to
/healthcheck/
endpoint (#1047)
* Add api_client fixture to conftest * Add ES check to healthcheck endpoint * Fix timeout format
- Loading branch information
1 parent
afcd7b8
commit 316815e
Showing
5 changed files
with
85 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from rest_framework.test import APIClient | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def api_client(): | ||
return APIClient() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pook | ||
import pytest | ||
|
||
|
||
def mock_health_response(status="green", timed_out=False): | ||
return ( | ||
pook.get(pook.regex(r"_cluster\/health")) | ||
.times(1) | ||
.reply(200) | ||
.json( | ||
{ | ||
"status": status if not timed_out else None, | ||
"timed_out": timed_out, | ||
} | ||
) | ||
) | ||
|
||
|
||
def test_health_check_plain(api_client): | ||
res = api_client.get("/healthcheck/") | ||
assert res.status_code == 200 | ||
|
||
|
||
def test_health_check_es_timed_out(api_client): | ||
mock_health_response(timed_out=True) | ||
pook.on() | ||
res = api_client.get("/healthcheck/", data={"check_es": True}) | ||
pook.off() | ||
|
||
assert res.status_code == 503 | ||
assert res.json()["detail"] == "es_timed_out" | ||
|
||
|
||
@pytest.mark.parametrize("status", ("yellow", "red")) | ||
def test_health_check_es_status_bad(status, api_client): | ||
mock_health_response(status=status) | ||
pook.on() | ||
res = api_client.get("/healthcheck/", data={"check_es": True}) | ||
pook.off() | ||
|
||
assert res.status_code == 503 | ||
assert res.json()["detail"] == f"es_status_{status}" | ||
|
||
|
||
def test_health_check_es_all_good(api_client): | ||
mock_health_response(status="green") | ||
pook.on() | ||
res = api_client.get("/healthcheck/", data={"check_es": True}) | ||
pook.off() | ||
|
||
assert res.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters