feat: /live and /ready respond with 500 on failure
503 is still used by /ready to indicate a transient state that can be recovered from.
This commit is contained in:
committed by
Steve Chavez
parent
f9e9740999
commit
0060abeb01
+11
-4
@@ -70,6 +70,13 @@ class PostgrestProcess:
|
||||
time.sleep(0.1)
|
||||
return output
|
||||
|
||||
def wait_until_scache_starts_loading(self, max_seconds=1):
|
||||
"Wait for the admin /ready return a status of 503"
|
||||
|
||||
wait_until_status_code(
|
||||
self.admin.baseurl + "/ready", max_seconds=max_seconds, status_code=503
|
||||
)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def run(
|
||||
@@ -120,7 +127,7 @@ def run(
|
||||
process.stdin.close()
|
||||
|
||||
if wait_for_readiness:
|
||||
wait_until_ready(adminurl + "/ready", wait_max_seconds)
|
||||
wait_until_status_code(adminurl + "/ready", wait_max_seconds, 200)
|
||||
|
||||
if no_startup_stdout:
|
||||
process.stdout.read()
|
||||
@@ -178,14 +185,14 @@ def wait_until_exit(postgrest):
|
||||
raise PostgrestTimedOut()
|
||||
|
||||
|
||||
def wait_until_ready(url, max_seconds):
|
||||
"Wait for the given HTTP endpoint to return a status of 200."
|
||||
def wait_until_status_code(url, max_seconds, status_code):
|
||||
"Wait for the given HTTP endpoint to return a status code"
|
||||
session = requests_unixsocket.Session()
|
||||
|
||||
for _ in range(max_seconds * 10):
|
||||
try:
|
||||
response = session.get(url, timeout=1)
|
||||
if response.status_code == 200:
|
||||
if response.status_code == status_code:
|
||||
return
|
||||
except (requests.ConnectionError, requests.ReadTimeout):
|
||||
pass
|
||||
|
||||
@@ -7,7 +7,7 @@ from util import *
|
||||
from postgrest import *
|
||||
|
||||
|
||||
def test_requests__wait_for_schema_cache_reload(defaultenv):
|
||||
def test_requests_wait_for_schema_cache_reload(defaultenv):
|
||||
"requests that use the schema cache (e.g. resource embedding) wait for the schema cache to reload"
|
||||
|
||||
env = {
|
||||
@@ -23,13 +23,14 @@ def test_requests__wait_for_schema_cache_reload(defaultenv):
|
||||
response = postgrest.session.get("/rpc/notify_pgrst")
|
||||
assert response.status_code == 204
|
||||
|
||||
time.sleep(1.5) # wait for schema cache to start reloading
|
||||
postgrest.wait_until_scache_starts_loading()
|
||||
|
||||
response = postgrest.session.get("/tpopmassn?select=*,tpop(*)")
|
||||
assert response.status_code == 200
|
||||
|
||||
server_timings = parse_server_timings_header(response.headers["Server-Timing"])
|
||||
plan_dur = server_timings["plan"]
|
||||
plan_dur = parse_server_timings_header(response.headers["Server-Timing"])[
|
||||
"plan"
|
||||
]
|
||||
assert plan_dur > 10000.0
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -739,7 +739,7 @@ def test_admin_ready_dependent_on_main_app(defaultenv):
|
||||
# delete the unix socket to make the main app fail
|
||||
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
||||
response = postgrest.admin.get("/ready")
|
||||
assert response.status_code == 503
|
||||
assert response.status_code == 500
|
||||
|
||||
|
||||
def test_admin_live_good(defaultenv):
|
||||
@@ -757,7 +757,7 @@ def test_admin_live_dependent_on_main_app(defaultenv):
|
||||
# delete the unix socket to make the main app fail
|
||||
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
||||
response = postgrest.admin.get("/live")
|
||||
assert response.status_code == 503
|
||||
assert response.status_code == 500
|
||||
|
||||
|
||||
@pytest.mark.parametrize("specialhostvalue", FIXTURES["specialhostvalues"])
|
||||
|
||||
Reference in New Issue
Block a user