diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3030d09e5c..b2bcfa0481 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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() @@ -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 diff --git a/nix/tools/devTools.nix b/nix/tools/devTools.nix index ad7639a322..114e5e4665 100644 --- a/nix/tools/devTools.nix +++ b/nix/tools/devTools.nix @@ -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 ''; diff --git a/nix/tools/tests.nix b/nix/tools/tests.nix index 92769e17e5..77010f88d9 100644 --- a/nix/tools/tests.nix +++ b/nix/tools/tests.nix @@ -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 = @@ -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 \ @@ -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 @@ -200,6 +219,7 @@ buildToolbox testDoctests testSpecIdempotence testIO + testBigSchema dumpSchema coverage coverageDraftOverlay; diff --git a/test/io/test_big_schema.py b/test/io/test_big_schema.py new file mode 100644 index 0000000000..86bfab2592 --- /dev/null +++ b/test/io/test_big_schema.py @@ -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 diff --git a/test/io/test_io.py b/test/io/test_io.py index fde5129552..ca4211502d 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -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" diff --git a/test/io/util.py b/test/io/util.py index 59ba556438..7a06100030 100644 --- a/test/io/util.py +++ b/test/io/util.py @@ -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