From a8feaadc0140b44b330ad7814863931ddc2d6a63 Mon Sep 17 00:00:00 2001 From: Taimoor Zaeem Date: Wed, 12 Aug 2026 14:02:16 +0500 Subject: [PATCH] test(io): move remaining tests in test_io.py to their modules We had just 3 tests remaining in test_io.py. This commit moves them to their modules. So we have: * test_graceful_shutdown.py * test_zero_downtime.py * test_pg_internal.py Signed-off-by: Taimoor Zaeem (cherry picked from commit 02d83d1c011f1c8472f5a5632d11ee65ba8f0340) --- test/io/test_graceful_shutdown.py | 25 +++++++++ test/io/test_pg_internal.py | 26 ++++++++++ test/io/{test_io.py => test_zero_downtime.py} | 52 +------------------ 3 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 test/io/test_graceful_shutdown.py create mode 100644 test/io/test_pg_internal.py rename test/io/{test_io.py => test_zero_downtime.py} (64%) 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"'