test: requests wait for schema cache load
* nix: add postgrest-test-big-schema command
This commit is contained in:
committed by
Steve Chavez
parent
92ac7e574e
commit
4b289b1c97
@@ -81,7 +81,7 @@ jobs:
|
|||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
||||||
tools: tests.testSpec.bin tests.testIO.bin withTools.postgresql-${{ matrix.pgVersion }}.bin
|
tools: tests.testSpec.bin tests.testIO.bin tests.testBigSchema.bin withTools.postgresql-${{ matrix.pgVersion }}.bin
|
||||||
|
|
||||||
- name: Run spec tests
|
- name: Run spec tests
|
||||||
if: always()
|
if: always()
|
||||||
@@ -91,6 +91,10 @@ jobs:
|
|||||||
if: always()
|
if: always()
|
||||||
run: postgrest-with-postgresql-${{ matrix.pgVersion }} postgrest-test-io -vv
|
run: postgrest-with-postgresql-${{ matrix.pgVersion }} postgrest-test-io -vv
|
||||||
|
|
||||||
|
- name: Run IO tests on a big schema
|
||||||
|
if: always()
|
||||||
|
run: postgrest-with-postgresql-${{ matrix.pgVersion }} postgrest-test-big-schema -vv
|
||||||
|
|
||||||
|
|
||||||
memory:
|
memory:
|
||||||
name: Memory
|
name: Memory
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ let
|
|||||||
${tests}/bin/postgrest-test-spec
|
${tests}/bin/postgrest-test-spec
|
||||||
${tests}/bin/postgrest-test-doctests
|
${tests}/bin/postgrest-test-doctests
|
||||||
${tests}/bin/postgrest-test-io
|
${tests}/bin/postgrest-test-io
|
||||||
|
${tests}/bin/postgrest-test-big-schema
|
||||||
${style}/bin/postgrest-lint
|
${style}/bin/postgrest-lint
|
||||||
${style}/bin/postgrest-style-check
|
${style}/bin/postgrest-style-check
|
||||||
'';
|
'';
|
||||||
|
|||||||
+23
-3
@@ -84,7 +84,22 @@ let
|
|||||||
''
|
''
|
||||||
${cabal-install}/bin/cabal v2-build ${devCabalOptions}
|
${cabal-install}/bin/cabal v2-build ${devCabalOptions}
|
||||||
${cabal-install}/bin/cabal v2-exec -- ${withTools.withPg} -f test/io/fixtures.sql \
|
${cabal-install}/bin/cabal v2-exec -- ${withTools.withPg} -f test/io/fixtures.sql \
|
||||||
${ioTestPython}/bin/pytest -v test/io "''${_arg_leftovers[@]}"
|
${ioTestPython}/bin/pytest --ignore=test/io/test_big_schema.py -v test/io "''${_arg_leftovers[@]}"
|
||||||
|
'';
|
||||||
|
|
||||||
|
testBigSchema =
|
||||||
|
checkedShellScript
|
||||||
|
{
|
||||||
|
name = "postgrest-test-big-schema";
|
||||||
|
docs = "Run a pytest-based IO test on a big schema. Add -k to run tests that match a given expression.";
|
||||||
|
args = [ "ARG_LEFTOVERS([pytest arguments])" ];
|
||||||
|
workingDir = "/";
|
||||||
|
withEnv = postgrest.env;
|
||||||
|
}
|
||||||
|
''
|
||||||
|
${cabal-install}/bin/cabal v2-build ${devCabalOptions}
|
||||||
|
${cabal-install}/bin/cabal v2-exec -- ${withTools.withPg} -f test/io/big_schema.sql \
|
||||||
|
${ioTestPython}/bin/pytest -v test/io/test_big_schema.py "''${_arg_leftovers[@]}"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
dumpSchema =
|
dumpSchema =
|
||||||
@@ -135,7 +150,11 @@ let
|
|||||||
# collect all tests
|
# collect all tests
|
||||||
HPCTIXFILE="$tmpdir"/io.tix \
|
HPCTIXFILE="$tmpdir"/io.tix \
|
||||||
${withTools.withPg} -f test/io/fixtures.sql \
|
${withTools.withPg} -f test/io/fixtures.sql \
|
||||||
${cabal-install}/bin/cabal v2-exec ${devCabalOptions} -- ${ioTestPython}/bin/pytest -v test/io
|
${cabal-install}/bin/cabal v2-exec ${devCabalOptions} -- ${ioTestPython}/bin/pytest --ignore=test/io/test_big_schema.py -v test/io
|
||||||
|
|
||||||
|
HPCTIXFILE="$tmpdir"/big_schema.tix \
|
||||||
|
${withTools.withPg} -f test/io/big_schema.sql \
|
||||||
|
${cabal-install}/bin/cabal v2-exec ${devCabalOptions} -- ${ioTestPython}/bin/pytest -v test/io/test_big_schema.py
|
||||||
|
|
||||||
HPCTIXFILE="$tmpdir"/spec.tix \
|
HPCTIXFILE="$tmpdir"/spec.tix \
|
||||||
${withTools.withPg} -f test/spec/fixtures/load.sql \
|
${withTools.withPg} -f test/spec/fixtures/load.sql \
|
||||||
@@ -145,7 +164,7 @@ let
|
|||||||
|
|
||||||
# collect all the tix files
|
# collect all the tix files
|
||||||
${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix \
|
${ghc}/bin/hpc sum --union --exclude=Paths_postgrest --output="$tmpdir"/tests.tix \
|
||||||
"$tmpdir"/io*.tix "$tmpdir"/spec.tix
|
"$tmpdir"/io*.tix "$tmpdir"/big_schema*.tix "$tmpdir"/spec.tix
|
||||||
|
|
||||||
# prepare the overlay
|
# prepare the overlay
|
||||||
${ghc}/bin/hpc overlay --output="$tmpdir"/overlay.tix test/coverage.overlay
|
${ghc}/bin/hpc overlay --output="$tmpdir"/overlay.tix test/coverage.overlay
|
||||||
@@ -200,6 +219,7 @@ buildToolbox
|
|||||||
testDoctests
|
testDoctests
|
||||||
testSpecIdempotence
|
testSpecIdempotence
|
||||||
testIO
|
testIO
|
||||||
|
testBigSchema
|
||||||
dumpSchema
|
dumpSchema
|
||||||
coverage
|
coverage
|
||||||
coverageDraftOverlay;
|
coverageDraftOverlay;
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
"IO tests for PostgREST started on the big schema."
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from config import *
|
||||||
|
from util import *
|
||||||
|
from postgrest import *
|
||||||
|
|
||||||
|
|
||||||
|
def test_requests_wait_for_schema_cache_to_be_loaded(defaultenv):
|
||||||
|
"requests that use the schema cache (e.g. resource embedding) wait for schema cache to be loaded"
|
||||||
|
|
||||||
|
env = {
|
||||||
|
**defaultenv,
|
||||||
|
"PGRST_DB_SCHEMAS": "apflora",
|
||||||
|
"PGRST_DB_POOL": "2",
|
||||||
|
"PGRST_DB_ANON_ROLE": "postgrest_test_anonymous",
|
||||||
|
"PGRST_SERVER_TIMING_ENABLED": "true",
|
||||||
|
}
|
||||||
|
|
||||||
|
with run(env=env, wait_for_readiness=False) as postgrest:
|
||||||
|
time.sleep(1.5) # manually wait for schema cache to start loading
|
||||||
|
|
||||||
|
response = postgrest.session.get("/tpopmassn?select=*,tpop(*)")
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
server_timings = parse_server_timings_header(response.headers["Server-Timing"])
|
||||||
|
plan_dur = server_timings["plan"]
|
||||||
|
assert plan_dur > 10000.0
|
||||||
|
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
# A stack size of 200K seems to be enough for succeess
|
||||||
|
@pytest.mark.skip
|
||||||
|
def test_openapi_in_big_schema(defaultenv):
|
||||||
|
"Should get a successful response from openapi on a big schema"
|
||||||
|
|
||||||
|
env = {
|
||||||
|
**defaultenv,
|
||||||
|
"PGRST_DB_SCHEMAS": "apflora",
|
||||||
|
"PGRST_OPENAPI_MODE": "ignore-privileges",
|
||||||
|
}
|
||||||
|
|
||||||
|
with run(env=env) as postgrest:
|
||||||
|
response = postgrest.session.get("/")
|
||||||
|
assert response.status_code == 200
|
||||||
@@ -1007,24 +1007,6 @@ def test_schema_cache_concurrent_notifications(slow_schema_cache_env):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
# A stack size of 200K seems to be enough for succeess
|
|
||||||
@pytest.mark.skip
|
|
||||||
def test_openapi_in_big_schema(defaultenv):
|
|
||||||
"Should get a successful response from openapi on a big schema"
|
|
||||||
|
|
||||||
env = {
|
|
||||||
**defaultenv,
|
|
||||||
"PGRST_DB_SCHEMAS": "apflora",
|
|
||||||
"PGRST_OPENAPI_MODE": "ignore-privileges",
|
|
||||||
}
|
|
||||||
|
|
||||||
with run(env=env) as postgrest:
|
|
||||||
response = postgrest.session.get("/")
|
|
||||||
assert response.status_code == 200
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("dburi_type", ["no_params", "no_params_qmark", "with_params"])
|
@pytest.mark.parametrize("dburi_type", ["no_params", "no_params_qmark", "with_params"])
|
||||||
def test_get_pgrst_version_with_uri_connection_string(dburi_type, dburi, defaultenv):
|
def test_get_pgrst_version_with_uri_connection_string(dburi_type, dburi, defaultenv):
|
||||||
"The fallback_application_name should be added to the db-uri if it has a URI format"
|
"The fallback_application_name should be added to the db-uri if it has a URI format"
|
||||||
|
|||||||
+1
-1
@@ -55,5 +55,5 @@ def parse_server_timings_header(header):
|
|||||||
for timing in header.split(","):
|
for timing in header.split(","):
|
||||||
name, duration_text, *_ = timing.split(";")
|
name, duration_text, *_ = timing.split(";")
|
||||||
_, duration = duration_text.split("=")
|
_, duration = duration_text.split("=")
|
||||||
timings[name] = float(duration)
|
timings[name.strip()] = float(duration)
|
||||||
return timings
|
return timings
|
||||||
|
|||||||
Reference in New Issue
Block a user