test: Make io tests use admin/ready to wait for startup
This commit is contained in:
committed by
Wolfgang Walther
parent
6bc965e2a0
commit
df5d9400fe
+13
-15
@@ -137,7 +137,7 @@ def dumpconfig(configpath=None, env=None, stdin=None):
|
|||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def run(configpath=None, stdin=None, env=None, port=None, adminport=None):
|
def run(configpath=None, stdin=None, env=None, port=None):
|
||||||
"Run PostgREST and yield an endpoint that is ready for connections."
|
"Run PostgREST and yield an endpoint that is ready for connections."
|
||||||
env = env or {}
|
env = env or {}
|
||||||
env["PGRST_DB_POOL"] = "1"
|
env["PGRST_DB_POOL"] = "1"
|
||||||
@@ -153,11 +153,9 @@ def run(configpath=None, stdin=None, env=None, port=None, adminport=None):
|
|||||||
env["PGRST_SERVER_UNIX_SOCKET"] = str(socketfile)
|
env["PGRST_SERVER_UNIX_SOCKET"] = str(socketfile)
|
||||||
baseurl = "http+unix://" + urllib.parse.quote_plus(str(socketfile))
|
baseurl = "http+unix://" + urllib.parse.quote_plus(str(socketfile))
|
||||||
|
|
||||||
if adminport:
|
adminport = freeport()
|
||||||
env["PGRST_ADMIN_SERVER_PORT"] = str(adminport)
|
env["PGRST_ADMIN_SERVER_PORT"] = str(adminport)
|
||||||
adminurl = f"http://localhost:{adminport}"
|
adminurl = f"http://localhost:{adminport}"
|
||||||
else:
|
|
||||||
adminurl = None
|
|
||||||
|
|
||||||
command = [POSTGREST_BIN]
|
command = [POSTGREST_BIN]
|
||||||
env["HPCTIXFILE"] = hpctixfile()
|
env["HPCTIXFILE"] = hpctixfile()
|
||||||
@@ -179,14 +177,14 @@ def run(configpath=None, stdin=None, env=None, port=None, adminport=None):
|
|||||||
process.stdin.write(stdin or b"")
|
process.stdin.write(stdin or b"")
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
|
|
||||||
wait_until_ready(baseurl)
|
wait_until_ready(adminurl + "/ready")
|
||||||
|
|
||||||
process.stdout.read()
|
process.stdout.read()
|
||||||
|
|
||||||
yield PostgrestProcess(
|
yield PostgrestProcess(
|
||||||
process=process,
|
process=process,
|
||||||
session=PostgrestSession(baseurl),
|
session=PostgrestSession(baseurl),
|
||||||
admin=PostgrestSession(adminurl) if adminurl else None,
|
admin=PostgrestSession(adminurl),
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
remaining_output = process.stdout.read()
|
remaining_output = process.stdout.read()
|
||||||
@@ -750,7 +748,7 @@ def test_admin_ready_w_channel(defaultenv):
|
|||||||
"PGRST_DB_CHANNEL_ENABLED": "true",
|
"PGRST_DB_CHANNEL_ENABLED": "true",
|
||||||
}
|
}
|
||||||
|
|
||||||
with run(env=env, adminport=freeport()) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
response = postgrest.admin.get("/ready")
|
response = postgrest.admin.get("/ready")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@@ -763,7 +761,7 @@ def test_admin_ready_wo_channel(defaultenv):
|
|||||||
"PGRST_DB_CHANNEL_ENABLED": "false",
|
"PGRST_DB_CHANNEL_ENABLED": "false",
|
||||||
}
|
}
|
||||||
|
|
||||||
with run(env=env, adminport=freeport()) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
response = postgrest.admin.get("/ready")
|
response = postgrest.admin.get("/ready")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@@ -780,7 +778,7 @@ def test_admin_ready_includes_schema_cache_state(defaultenv):
|
|||||||
"PGRST_DB_ANON_ROLE": "limited_authenticator",
|
"PGRST_DB_ANON_ROLE": "limited_authenticator",
|
||||||
}
|
}
|
||||||
|
|
||||||
with run(env=env, adminport=freeport()) as postgrest:
|
with run(env=env) as postgrest:
|
||||||
|
|
||||||
# make it impossible to load the schema cache
|
# make it impossible to load the schema cache
|
||||||
response = postgrest.session.post(
|
response = postgrest.session.post(
|
||||||
@@ -802,7 +800,7 @@ def test_admin_ready_includes_schema_cache_state(defaultenv):
|
|||||||
def test_admin_not_found(defaultenv):
|
def test_admin_not_found(defaultenv):
|
||||||
"Should get a not found from a undefined endpoint on the admin server"
|
"Should get a not found from a undefined endpoint on the admin server"
|
||||||
|
|
||||||
with run(env=defaultenv, adminport=freeport()) as postgrest:
|
with run(env=defaultenv) as postgrest:
|
||||||
response = postgrest.admin.get("/notfound")
|
response = postgrest.admin.get("/notfound")
|
||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
|
|
||||||
@@ -810,7 +808,7 @@ def test_admin_not_found(defaultenv):
|
|||||||
def test_admin_ready_dependent_on_main_app(defaultenv):
|
def test_admin_ready_dependent_on_main_app(defaultenv):
|
||||||
"Should get a failure from the admin ready endpoint if the main app also fails"
|
"Should get a failure from the admin ready endpoint if the main app also fails"
|
||||||
|
|
||||||
with run(env=defaultenv, adminport=freeport()) as postgrest:
|
with run(env=defaultenv) as postgrest:
|
||||||
# delete the unix socket to make the main app fail
|
# delete the unix socket to make the main app fail
|
||||||
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
||||||
response = postgrest.admin.get("/ready")
|
response = postgrest.admin.get("/ready")
|
||||||
@@ -820,7 +818,7 @@ def test_admin_ready_dependent_on_main_app(defaultenv):
|
|||||||
def test_admin_live_good(defaultenv):
|
def test_admin_live_good(defaultenv):
|
||||||
"Should get a success from the admin live endpoint if the main app is running"
|
"Should get a success from the admin live endpoint if the main app is running"
|
||||||
|
|
||||||
with run(env=defaultenv, port=freeport(), adminport=freeport()) as postgrest:
|
with run(env=defaultenv, port=freeport()) as postgrest:
|
||||||
response = postgrest.admin.get("/live")
|
response = postgrest.admin.get("/live")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@@ -828,7 +826,7 @@ def test_admin_live_good(defaultenv):
|
|||||||
def test_admin_live_dependent_on_main_app(defaultenv):
|
def test_admin_live_dependent_on_main_app(defaultenv):
|
||||||
"Should get a failure from the admin live endpoint if the main app also fails"
|
"Should get a failure from the admin live endpoint if the main app also fails"
|
||||||
|
|
||||||
with run(env=defaultenv, adminport=freeport()) as postgrest:
|
with run(env=defaultenv) as postgrest:
|
||||||
# delete the unix socket to make the main app fail
|
# delete the unix socket to make the main app fail
|
||||||
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
|
||||||
response = postgrest.admin.get("/live")
|
response = postgrest.admin.get("/live")
|
||||||
|
|||||||
Reference in New Issue
Block a user