test: move prepared statements config related tests to spec tests
Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
@@ -260,6 +260,7 @@ test-suite spec
|
||||
Feature.Query.Preferences.HandlingSpec
|
||||
Feature.Query.Preferences.MaxAffectedSpec
|
||||
Feature.Query.Preferences.TimezoneSpec
|
||||
Feature.Query.PreparedStatementsSpec
|
||||
Feature.Query.QueryLimitedSpec
|
||||
Feature.Query.QuerySpec
|
||||
Feature.Query.RangeSpec
|
||||
|
||||
@@ -512,23 +512,6 @@
|
||||
pdSchema: public
|
||||
pdVolatility: Volatile
|
||||
|
||||
- - qiName: uses_prepared_statements
|
||||
qiSchema: public
|
||||
- - pdDescription: null
|
||||
pdFuncSettings: []
|
||||
pdHasVariadic: false
|
||||
pdName: uses_prepared_statements
|
||||
pdParams: []
|
||||
pdReturnType:
|
||||
contents:
|
||||
contents:
|
||||
qiName: bool
|
||||
qiSchema: pg_catalog
|
||||
tag: Scalar
|
||||
tag: Single
|
||||
pdSchema: public
|
||||
pdVolatility: Volatile
|
||||
|
||||
- - qiName: repeatable_read_isolation_level
|
||||
qiSchema: public
|
||||
- - pdDescription: null
|
||||
|
||||
@@ -54,10 +54,6 @@ create function v1.get_guc_value(name text) returns text as $$
|
||||
select nullif(current_setting(name), '')::text;
|
||||
$$ language sql;
|
||||
|
||||
create function uses_prepared_statements() returns bool as $$
|
||||
select count(name) > 0 from pg_catalog.pg_prepared_statements
|
||||
$$ language sql;
|
||||
|
||||
create function change_max_rows_config(val int, notify bool default false) returns void as $_$
|
||||
begin
|
||||
execute format($$
|
||||
|
||||
@@ -420,27 +420,6 @@ def test_notify_do_nothing(defaultenv):
|
||||
assert output == []
|
||||
|
||||
|
||||
def test_db_prepared_statements_enable(defaultenv):
|
||||
"Should use prepared statements when the setting is enabled."
|
||||
|
||||
with run(env=defaultenv) as postgrest:
|
||||
response = postgrest.session.post("/rpc/uses_prepared_statements")
|
||||
assert response.text == "true"
|
||||
|
||||
|
||||
def test_db_prepared_statements_disable(defaultenv):
|
||||
"Should not use any prepared statements when the setting is disabled."
|
||||
|
||||
env = {
|
||||
**defaultenv,
|
||||
"PGRST_DB_PREPARED_STATEMENTS": "false",
|
||||
}
|
||||
|
||||
with run(env=env) as postgrest:
|
||||
response = postgrest.session.post("/rpc/uses_prepared_statements")
|
||||
assert response.text == "false"
|
||||
|
||||
|
||||
def test_statement_timeout(defaultenv, metapostgrest):
|
||||
"Statement timeout times out slow statements"
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
module Feature.Query.PreparedStatementsSpec where
|
||||
|
||||
import Network.HTTP.Types
|
||||
import Test.Hspec hiding (pendingWith)
|
||||
import Test.Hspec.Wai
|
||||
import Text.Heredoc
|
||||
|
||||
import PostgREST.Config (AppConfig (..))
|
||||
|
||||
import Protolude hiding (get)
|
||||
import SpecHelper
|
||||
|
||||
spec :: SpecWithConfig
|
||||
spec withConfig = do
|
||||
withConfig baseCfg { configDbPreparedStatements = True } $
|
||||
it "should use prepared statements when the setting is enabled" $
|
||||
request methodPost "/rpc/uses_prepared_statements"
|
||||
[] ""
|
||||
`shouldRespondWith`
|
||||
[str|true|]
|
||||
{ matchStatus = 200 }
|
||||
|
||||
withConfig baseCfg { configDbPreparedStatements = False } $
|
||||
it "should not use any prepared statements when the setting is disabled" $ do
|
||||
request methodGet "/never_prepared"
|
||||
[] ""
|
||||
`shouldRespondWith` 200
|
||||
|
||||
request methodPost "/rpc/never_uses_prepared_statements"
|
||||
[] ""
|
||||
`shouldRespondWith`
|
||||
[str|true|]
|
||||
{ matchStatus = 200 }
|
||||
@@ -58,6 +58,7 @@ import qualified Feature.Query.PostGISSpec
|
||||
import qualified Feature.Query.Preferences.HandlingSpec
|
||||
import qualified Feature.Query.Preferences.MaxAffectedSpec
|
||||
import qualified Feature.Query.Preferences.TimezoneSpec
|
||||
import qualified Feature.Query.PreparedStatementsSpec
|
||||
import qualified Feature.Query.QueryLimitedSpec
|
||||
import qualified Feature.Query.QuerySpec
|
||||
import qualified Feature.Query.RangeSpec
|
||||
@@ -148,6 +149,7 @@ main = do
|
||||
, ("Feature.Query.Preferences.HandlingSpec" , Feature.Query.Preferences.HandlingSpec.spec)
|
||||
, ("Feature.Query.Preferences.MaxAffectedSpec" , Feature.Query.Preferences.MaxAffectedSpec.spec)
|
||||
, ("Feature.Query.Preferences.TimezoneSpec.enabledSpec", Feature.Query.Preferences.TimezoneSpec.enabledSpec)
|
||||
, ("Feature.Query.PreparedStatementsSpec.spec" , Feature.Query.PreparedStatementsSpec.spec)
|
||||
, ("Feature.Query.QueryLimitedSpec" , Feature.Query.QueryLimitedSpec.spec)
|
||||
, ("Feature.Query.QuerySpec" , Feature.Query.QuerySpec.spec actualPgVersion)
|
||||
, ("Feature.Query.RangeSpec" , Feature.Query.RangeSpec.spec)
|
||||
|
||||
Vendored
+11
@@ -3881,3 +3881,14 @@ $$ language plpgsql;
|
||||
create or replace function "true"() returns boolean as $_$
|
||||
select true;
|
||||
$_$ language sql;
|
||||
|
||||
create function uses_prepared_statements() returns bool as $$
|
||||
select count(*) > 0 from pg_catalog.pg_prepared_statements;
|
||||
$$ language sql;
|
||||
|
||||
create table never_prepared (id int);
|
||||
|
||||
create function never_uses_prepared_statements() returns bool as $$
|
||||
select count(*) = 0 from pg_catalog.pg_prepared_statements
|
||||
where statement ilike '%never_prepared%';
|
||||
$$ language sql;
|
||||
|
||||
Reference in New Issue
Block a user