test: no empty tx started for invalid path/method
This commit is contained in:
committed by
Steve Chavez
parent
23e4c7fe6e
commit
df49f482dc
+2
-2
@@ -90,7 +90,7 @@ let
|
|||||||
checkedShellScript
|
checkedShellScript
|
||||||
{
|
{
|
||||||
name = "postgrest-test-io";
|
name = "postgrest-test-io";
|
||||||
docs = "Run the pytest-based IO tests.";
|
docs = "Run the pytest-based IO tests. Add -k to run tests that match a given expression.";
|
||||||
args = [ "ARG_LEFTOVERS([pytest arguments])" ];
|
args = [ "ARG_LEFTOVERS([pytest arguments])" ];
|
||||||
inRootDir = true;
|
inRootDir = true;
|
||||||
withEnv = postgrest.env;
|
withEnv = postgrest.env;
|
||||||
@@ -151,7 +151,7 @@ let
|
|||||||
HPCTIXFILE="$tmpdir"/io.tix \
|
HPCTIXFILE="$tmpdir"/io.tix \
|
||||||
${withTools.withPg} -f test/io/fixtures.sql ${cabal-install}/bin/cabal v2-exec ${devCabalOptions} -- \
|
${withTools.withPg} -f test/io/fixtures.sql ${cabal-install}/bin/cabal v2-exec ${devCabalOptions} -- \
|
||||||
${ioTestPython}/bin/pytest -v test/io
|
${ioTestPython}/bin/pytest -v test/io
|
||||||
|
|
||||||
HPCTIXFILE="$tmpdir"/spec.tix \
|
HPCTIXFILE="$tmpdir"/spec.tix \
|
||||||
${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} test:spec
|
${withTools.withPg} ${cabal-install}/bin/cabal v2-run ${devCabalOptions} test:spec
|
||||||
|
|
||||||
|
|||||||
@@ -78,3 +78,11 @@ create function reload_pgrst_config() returns void as $_$
|
|||||||
begin
|
begin
|
||||||
perform pg_notify('pgrst', 'reload config');
|
perform pg_notify('pgrst', 'reload config');
|
||||||
end $_$ language plpgsql ;
|
end $_$ language plpgsql ;
|
||||||
|
|
||||||
|
create or replace function sleep(seconds double precision) returns void as $$
|
||||||
|
select pg_sleep(seconds);
|
||||||
|
$$ language sql;
|
||||||
|
|
||||||
|
create or replace function hello() returns text as $$
|
||||||
|
select 'hello';
|
||||||
|
$$ language sql;
|
||||||
|
|||||||
@@ -943,6 +943,34 @@ def test_log_level(level, has_output, defaultenv):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_pool_connection_required_on_bad_http_logic(defaultenv):
|
||||||
|
"no pool connection should be consumed for failing on invalid http logic"
|
||||||
|
|
||||||
|
env = {
|
||||||
|
**defaultenv,
|
||||||
|
"PGRST_DB_POOL": "1",
|
||||||
|
}
|
||||||
|
|
||||||
|
with run(env=env) as postgrest:
|
||||||
|
# First we retain the only pool connection available
|
||||||
|
# The try/except is a hack for not waiting for the response, taken from https://stackoverflow.com/a/45601591/4692662
|
||||||
|
try:
|
||||||
|
postgrest.session.get("/rpc/sleep?seconds=50", timeout=0.1)
|
||||||
|
except requests.exceptions.ReadTimeout:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Then the following requests should succeed rapidly
|
||||||
|
|
||||||
|
# not found nested route shouldn't require opening a connection
|
||||||
|
response = postgrest.session.head("/path/notfound")
|
||||||
|
assert response.status_code == 404
|
||||||
|
|
||||||
|
# an invalid http method on a resource shouldn't require opening a connection
|
||||||
|
response = postgrest.session.request("TRACE", "/projects")
|
||||||
|
assert response.status_code == 405
|
||||||
|
response = postgrest.session.patch("/rpc/hello")
|
||||||
|
assert response.status_code == 405
|
||||||
|
|
||||||
# TODO: This test fails now because of https://github.com/PostgREST/postgrest/pull/2122
|
# TODO: This test fails now because of https://github.com/PostgREST/postgrest/pull/2122
|
||||||
# The stack size of 1K(-with-rtsopts=-K1K) is not enough and this fails with "stack overflow"
|
# The stack size of 1K(-with-rtsopts=-K1K) is not enough and this fails with "stack overflow"
|
||||||
# A stack size of 200K seems to be enough for succeess
|
# A stack size of 200K seems to be enough for succeess
|
||||||
|
|||||||
Reference in New Issue
Block a user