Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: requests wait for schema cache load #3328

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
uses: ./.github/actions/setup-nix
with:
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
if: always()
Expand All @@ -91,6 +91,10 @@ jobs:
if: always()
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:
name: Memory
Expand Down
1 change: 1 addition & 0 deletions nix/tools/devTools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ let
${tests}/bin/postgrest-test-spec
${tests}/bin/postgrest-test-doctests
${tests}/bin/postgrest-test-io
${tests}/bin/postgrest-test-big-schema
${style}/bin/postgrest-lint
${style}/bin/postgrest-style-check
'';
Expand Down
26 changes: 23 additions & 3 deletions nix/tools/tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,22 @@ let
''
${cabal-install}/bin/cabal v2-build ${devCabalOptions}
${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 =
Expand Down Expand Up @@ -135,7 +150,11 @@ let
# collect all tests
HPCTIXFILE="$tmpdir"/io.tix \
${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 \
${withTools.withPg} -f test/spec/fixtures/load.sql \
Expand All @@ -145,7 +164,7 @@ let

# collect all the tix files
${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
${ghc}/bin/hpc overlay --output="$tmpdir"/overlay.tix test/coverage.overlay
Expand Down Expand Up @@ -200,6 +219,7 @@ buildToolbox
testDoctests
testSpecIdempotence
testIO
testBigSchema
dumpSchema
coverage
coverageDraftOverlay;
Expand Down
47 changes: 47 additions & 0 deletions test/io/test_big_schema.py
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +10 to +29
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the gist of the PR



# 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
18 changes: 0 additions & 18 deletions test/io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,24 +1007,6 @@ def test_schema_cache_concurrent_notifications(slow_schema_cache_env):
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"])
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"
Expand Down
2 changes: 1 addition & 1 deletion test/io/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def parse_server_timings_header(header):
for timing in header.split(","):
name, duration_text, *_ = timing.split(";")
_, duration = duration_text.split("=")
timings[name] = float(duration)
timings[name.strip()] = float(duration)
return timings
Loading