Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make io tests use admin/ready to wait for startup #2116

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions test/io-tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def dumpconfig(configpath=None, env=None, stdin=None):


@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."
env = env or {}
env["PGRST_DB_POOL"] = "1"
Expand All @@ -153,11 +153,9 @@ def run(configpath=None, stdin=None, env=None, port=None, adminport=None):
env["PGRST_SERVER_UNIX_SOCKET"] = str(socketfile)
baseurl = "http+unix://" + urllib.parse.quote_plus(str(socketfile))

if adminport:
env["PGRST_ADMIN_SERVER_PORT"] = str(adminport)
adminurl = f"http://localhost:{adminport}"
else:
adminurl = None
adminport = freeport()
env["PGRST_ADMIN_SERVER_PORT"] = str(adminport)
adminurl = f"http://localhost:{adminport}"

command = [POSTGREST_BIN]
env["HPCTIXFILE"] = hpctixfile()
Expand All @@ -179,14 +177,14 @@ def run(configpath=None, stdin=None, env=None, port=None, adminport=None):
process.stdin.write(stdin or b"")
process.stdin.close()

wait_until_ready(baseurl)
wait_until_ready(adminurl + "/ready")

process.stdout.read()

yield PostgrestProcess(
process=process,
session=PostgrestSession(baseurl),
admin=PostgrestSession(adminurl) if adminurl else None,
admin=PostgrestSession(adminurl),
)
finally:
remaining_output = process.stdout.read()
Expand Down Expand Up @@ -750,7 +748,7 @@ def test_admin_ready_w_channel(defaultenv):
"PGRST_DB_CHANNEL_ENABLED": "true",
}

with run(env=env, adminport=freeport()) as postgrest:
with run(env=env) as postgrest:
response = postgrest.admin.get("/ready")
assert response.status_code == 200

Expand All @@ -763,7 +761,7 @@ def test_admin_ready_wo_channel(defaultenv):
"PGRST_DB_CHANNEL_ENABLED": "false",
}

with run(env=env, adminport=freeport()) as postgrest:
with run(env=env) as postgrest:
response = postgrest.admin.get("/ready")
assert response.status_code == 200

Expand All @@ -780,7 +778,7 @@ def test_admin_ready_includes_schema_cache_state(defaultenv):
"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
response = postgrest.session.post(
Expand All @@ -802,15 +800,15 @@ def test_admin_ready_includes_schema_cache_state(defaultenv):
def test_admin_not_found(defaultenv):
"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")
assert response.status_code == 404


def test_admin_ready_dependent_on_main_app(defaultenv):
"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
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
response = postgrest.admin.get("/ready")
Expand All @@ -820,15 +818,15 @@ def test_admin_ready_dependent_on_main_app(defaultenv):
def test_admin_live_good(defaultenv):
"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")
assert response.status_code == 200


def test_admin_live_dependent_on_main_app(defaultenv):
"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
os.remove(defaultenv["PGRST_SERVER_UNIX_SOCKET"])
response = postgrest.admin.get("/live")
Expand Down