diff --git a/test/io/test_graceful_shutdown.py b/test/io/test_graceful_shutdown.py new file mode 100644 index 000000000..071a2befa --- /dev/null +++ b/test/io/test_graceful_shutdown.py @@ -0,0 +1,25 @@ +import time + +from util import Thread +from postgrest import run + + +def test_graceful_shutdown_waits_for_in_flight_request(defaultenv): + "SIGTERM should allow in-flight requests to finish before exiting" + + with run(env=defaultenv, wait_max_seconds=5) as postgrest: + + def sleep(): + response = postgrest.session.get("/rpc/sleep?seconds=3", timeout=10) + assert response.text == "" + assert response.status_code == 204 + + t = Thread(target=sleep) + t.start() + + # Wait for the request to be in-flight before shutting down. + time.sleep(1) + + postgrest.process.terminate() + + t.join() diff --git a/test/io/test_pg_internal.py b/test/io/test_pg_internal.py new file mode 100644 index 000000000..0fe0bda48 --- /dev/null +++ b/test/io/test_pg_internal.py @@ -0,0 +1,26 @@ +from util import psql_as_superuser +from postgrest import run + + +def test_listener_query_is_visible_in_pg_stat_activity(defaultenv): + "The listener connection should show the LISTEN pgrst statement in pg_stat_activity" + + env = { + **defaultenv, + "PGRST_DB_CHANNEL_ENABLED": "true", + "PGAPPNAME": "listener-query-test", + } + + with run(env=env): + output = psql_as_superuser( + """ + select query + from pg_stat_activity + where application_name = 'listener-query-test' + and query = 'LISTEN "pgrst"' + limit 1; + """, + capture_output=True, + ).strip() + + assert output == 'LISTEN "pgrst"' diff --git a/test/io/test_io.py b/test/io/test_zero_downtime.py similarity index 64% rename from test/io/test_io.py rename to test/io/test_zero_downtime.py index 57c3fd322..09df284bb 100644 --- a/test/io/test_io.py +++ b/test/io/test_zero_downtime.py @@ -1,11 +1,6 @@ -"Unit tests for Input/Ouput of PostgREST seen as a black box." - import time -from util import ( - Thread, - psql_as_superuser, -) +from util import Thread from postgrest import ( freeport, run, @@ -13,27 +8,6 @@ from postgrest import ( ) -def test_graceful_shutdown_waits_for_in_flight_request(defaultenv): - "SIGTERM should allow in-flight requests to finish before exiting" - - with run(env=defaultenv, wait_max_seconds=5) as postgrest: - - def sleep(): - response = postgrest.session.get("/rpc/sleep?seconds=3", timeout=10) - assert response.text == "" - assert response.status_code == 204 - - t = Thread(target=sleep) - t.start() - - # Wait for the request to be in-flight before shutting down. - time.sleep(1) - - postgrest.process.terminate() - - t.join() - - def test_so_reuseport_zero_downtime_handover(defaultenv): "A second PostgREST instance should take over on the same main/admin ports without request failures." @@ -99,27 +73,3 @@ def test_so_reuseport_zero_downtime_handover(defaultenv): requester.join() assert failures == [] - - -def test_listener_query_is_visible_in_pg_stat_activity(defaultenv): - "The listener connection should show the LISTEN pgrst statement in pg_stat_activity" - - env = { - **defaultenv, - "PGRST_DB_CHANNEL_ENABLED": "true", - "PGAPPNAME": "listener-query-test", - } - - with run(env=env): - output = psql_as_superuser( - """ - select query - from pg_stat_activity - where application_name = 'listener-query-test' - and query = 'LISTEN "pgrst"' - limit 1; - """, - capture_output=True, - ).strip() - - assert output == 'LISTEN "pgrst"'