feat: apply all function settings as transaction-scoped settings

This commit is contained in:
Taimoor Zaeem
2024-02-09 11:37:01 -05:00
committed by Steve Chavez
parent 49584728b6
commit f9ee1f7e73
7 changed files with 99 additions and 59 deletions
+11
View File
@@ -198,3 +198,14 @@ $$ language sql set statement_timeout = '4s';
create function get_postgres_version() returns int as $$
select current_setting('server_version_num')::int;
$$ language sql;
create or replace function work_mem_test() returns text as $$
select current_setting('work_mem',false);
$$ language sql set work_mem = '6000';
create or replace function multiple_func_settings_test() returns setof record as $$
select current_setting('work_mem',false) as work_mem,
current_setting('statement_timeout',false) as statement_timeout;
$$ language sql
set work_mem = '5000'
set statement_timeout = '10s';
+40 -22
View File
@@ -1337,28 +1337,6 @@ def test_no_preflight_request_with_CORS_config_should_not_return_header(defaulte
assert "Access-Control-Allow-Origin" not in response.headers
def test_fail_with_3_sec_statement_and_1_sec_statement_timeout(defaultenv):
"statement that takes three seconds to execute should fail with one second timeout"
with run(env=defaultenv) as postgrest:
response = postgrest.session.post("/rpc/one_sec_timeout")
assert response.status_code == 500
assert (
response.text
== '{"code":"57014","details":null,"hint":null,"message":"canceling statement due to statement timeout"}'
)
def test_passes_with_3_sec_statement_and_4_sec_statement_timeout(defaultenv):
"statement that takes three seconds to execute should succeed with four second timeout"
with run(env=defaultenv) as postgrest:
response = postgrest.session.post("/rpc/four_sec_timeout")
assert response.status_code == 204
@pytest.mark.parametrize("level", ["crit", "error", "warn", "info"])
def test_db_error_logging_to_stderr(level, defaultenv, metapostgrest):
"verify that DB errors are logged to stderr"
@@ -1385,3 +1363,43 @@ def test_db_error_logging_to_stderr(level, defaultenv, metapostgrest):
else:
assert " 500 " in output[0]
assert "canceling statement due to statement timeout" in output[1]
def test_function_setting_statement_timeout_fails(defaultenv):
"statement that takes three seconds to execute should fail with one second timeout"
with run(env=defaultenv) as postgrest:
response = postgrest.session.post("/rpc/one_sec_timeout")
assert response.status_code == 500
assert (
response.text
== '{"code":"57014","details":null,"hint":null,"message":"canceling statement due to statement timeout"}'
)
def test_function_setting_statement_timeout_passes(defaultenv):
"statement that takes three seconds to execute should succeed with four second timeout"
with run(env=defaultenv) as postgrest:
response = postgrest.session.post("/rpc/four_sec_timeout")
assert response.status_code == 204
def test_function_setting_work_mem(defaultenv):
"check function setting work_mem is applied"
with run(env=defaultenv) as postgrest:
response = postgrest.session.post("/rpc/work_mem_test")
assert response.text == '"6000kB"'
def test_multiple_func_settings(defaultenv):
"check multiple function settings are applied"
with run(env=defaultenv) as postgrest:
response = postgrest.session.post("/rpc/multiple_func_settings_test")
assert response.text == '[{"work_mem":"5000kB","statement_timeout":"10s"}]'