From 95e36fdad95d93e9d75f8befcf3c7f85dbe7c6a2 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sun, 30 Mar 2025 18:43:45 +0200 Subject: [PATCH] nix: avoid rebuilding memory tests when entering nix-shell The memory tests are now run in the same way as the regular tests. --- .github/workflows/test.yaml | 2 +- .gitignore | 2 +- default.nix | 4 --- nix/tools/cabalTools.nix | 30 ++++++++++++++++++++++ nix/tools/memory.nix | 51 ------------------------------------- nix/tools/tests.nix | 20 ++++++++++++++- shell.nix | 1 - test/memory/memory-tests.sh | 18 ++++++------- 8 files changed, 60 insertions(+), 68 deletions(-) delete mode 100644 nix/tools/memory.nix diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7bff947ee..b01b3c81d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -105,7 +105,7 @@ jobs: uses: ./.github/actions/setup-nix with: authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - tools: memory.test.bin + tools: tests.testMemory.bin - name: Run memory tests run: postgrest-test-memory diff --git a/.gitignore b/.gitignore index 49b3be51b..986da1505 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ site .#* *.swp result* -dist-newstyle +dist-* postgrest.hp postgrest.prof __pycache__ diff --git a/default.nix b/default.nix index b8bd65568..32f3edafb 100644 --- a/default.nix +++ b/default.nix @@ -123,10 +123,6 @@ rec { loadtest = pkgs.callPackage nix/tools/loadtest.nix { inherit withTools; }; - # Script for running memory tests. - memory = - pkgs.callPackage nix/tools/memory.nix { inherit postgrestProfiled withTools; }; - # Scripts for publishing new releases. release = pkgs.callPackage nix/tools/release.nix { }; diff --git a/nix/tools/cabalTools.nix b/nix/tools/cabalTools.nix index 3cfe689cb..17954d0a2 100644 --- a/nix/tools/cabalTools.nix +++ b/nix/tools/cabalTools.nix @@ -60,6 +60,35 @@ let postgrest "''${_arg_leftovers[@]}" ''; + + runProfiled = + checkedShellScript + { + name = "postgrest-profiled-run"; + docs = "Run a profiled build of postgREST. This will generate a postgrest.prof file that can be used to do optimization."; + args = + [ + "ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [PostgREST anonymous role])" + "ARG_USE_ENV([PGRST_DB_POOL], [1], [PostgREST pool size])" + "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool timeout])" + "ARG_USE_ENV([PGRST_JWT_SECRET], [reallyreallyreallyreallyverysafe], [PostgREST JWT secret])" + "ARG_LEFTOVERS([PostgREST arguments])" + ]; + workingDir = "/"; + withEnv = postgrest.env; + } + '' + export PGRST_DB_ANON_ROLE + export PGRST_DB_POOL + export PGRST_DB_POOL_ACQUISITION_TIMEOUT + export PGRST_JWT_SECRET + + ${cabal-install}/bin/cabal v2-update + ${cabal-install}/bin/cabal --builddir="dist-prof" v2-build --enable-profiling --disable-shared exe:postgrest + ${cabal-install}/bin/cabal --builddir="dist-prof" v2-run -- \ + postgrest +RTS -p -h -RTS "''${_arg_leftovers[@]}" + ''; + repl = checkedShellScript { @@ -81,6 +110,7 @@ buildToolbox build clean run + runProfiled repl; }; } diff --git a/nix/tools/memory.nix b/nix/tools/memory.nix deleted file mode 100644 index a39178afe..000000000 --- a/nix/tools/memory.nix +++ /dev/null @@ -1,51 +0,0 @@ -# The memory tests have large dependencies (a profiled build of PostgREST) -# and are run less often than the spec tests, so we don't include them in -# the default test environment. We make them available through a separate module. -# TODO both of these require reentering the nix-shell if you make a change to the code -{ buildToolbox -, checkedShellScript -, curl -, postgrestProfiled -, withTools -}: -let - test = - checkedShellScript - { - name = "postgrest-test-memory"; - docs = "Run the memory tests."; - workingDir = "/"; - withPath = [ postgrestProfiled curl ]; - } - '' - ${withTools.withPg} -f test/spec/fixtures/load.sql test/memory/memory-tests.sh - ''; - - runProfiled = - checkedShellScript - { - name = "postgrest-profiled-run"; - docs = "Run a profiled build of postgREST. This will generate a postgrest.prof file that can be used to do optimization. Note: if you make a change to the code, you must reenter the nix-shell for an updated profiled build."; - args = - [ - "ARG_USE_ENV([PGRST_DB_ANON_ROLE], [postgrest_test_anonymous], [PostgREST anonymous role])" - "ARG_USE_ENV([PGRST_DB_POOL], [1], [PostgREST pool size])" - "ARG_USE_ENV([PGRST_DB_POOL_ACQUISITION_TIMEOUT], [1], [PostgREST pool timeout])" - "ARG_LEFTOVERS([PostgREST arguments])" - ]; - workingDir = "/"; - withPath = [ postgrestProfiled ]; - } - '' - export PGRST_DB_ANON_ROLE - export PGRST_DB_POOL - export PGRST_DB_POOL_ACQUISITION_TIMEOUT - - postgrest +RTS -p -h -RTS "''${_arg_leftovers[@]}" - ''; -in -buildToolbox -{ - name = "postgrest-memory"; - tools = { inherit test runProfiled; }; -} diff --git a/nix/tools/tests.nix b/nix/tools/tests.nix index 133c79cd2..c27c9ee7c 100644 --- a/nix/tools/tests.nix +++ b/nix/tools/tests.nix @@ -1,6 +1,7 @@ { buildToolbox , cabal-install , checkedShellScript +, curl , devCabalOptions , ghc , glibcLocales ? null @@ -235,6 +236,22 @@ let sed -i 's|^module \(.*\):|module \1/|g' test/coverage.overlay ''; + testMemory = + checkedShellScript + { + name = "postgrest-test-memory"; + docs = "Run the memory tests."; + workingDir = "/"; + withEnv = postgrest.env; + withPath = [ curl ]; + } + '' + ${cabal-install}/bin/cabal v2-update + ${cabal-install}/bin/cabal --builddir="dist-prof" v2-build --enable-profiling --disable-shared exe:postgrest + ${cabal-install}/bin/cabal --builddir="dist-prof" v2-exec -- ${withTools.withPg} -f test/spec/fixtures/load.sql \ + test/memory/memory-tests.sh + ''; + in buildToolbox { @@ -249,6 +266,7 @@ buildToolbox testReplica dumpSchema coverage - coverageDraftOverlay; + coverageDraftOverlay + testMemory; }; } diff --git a/shell.nix b/shell.nix index 854d3b05e..c82add7b8 100644 --- a/shell.nix +++ b/shell.nix @@ -22,7 +22,6 @@ let postgrest.devTools postgrest.docs postgrest.loadtest - postgrest.memory postgrest.release postgrest.style postgrest.tests diff --git a/test/memory/memory-tests.sh b/test/memory/memory-tests.sh index dfd0ea0cf..5b9a18405 100755 --- a/test/memory/memory-tests.sh +++ b/test/memory/memory-tests.sh @@ -102,21 +102,21 @@ postJsonArrayTest(){ echo "Running memory usage tests.." -jsonKeyTest "1M" "POST" "/rpc/leak?columns=blob" "27M" -jsonKeyTest "1M" "POST" "/leak?columns=blob" "21M" -jsonKeyTest "1M" "PATCH" "/leak?id=eq.1&columns=blob" "21M" +jsonKeyTest "1M" "POST" "/rpc/leak?columns=blob" "22M" +jsonKeyTest "1M" "POST" "/leak?columns=blob" "22M" +jsonKeyTest "1M" "PATCH" "/leak?id=eq.1&columns=blob" "22M" jsonKeyTest "10M" "POST" "/rpc/leak?columns=blob" "32M" jsonKeyTest "10M" "POST" "/leak?columns=blob" "32M" jsonKeyTest "10M" "PATCH" "/leak?id=eq.1&columns=blob" "32M" -jsonKeyTest "50M" "POST" "/rpc/leak?columns=blob" "72M" -jsonKeyTest "50M" "POST" "/leak?columns=blob" "72M" -jsonKeyTest "50M" "PATCH" "/leak?id=eq.1&columns=blob" "72M" +jsonKeyTest "50M" "POST" "/rpc/leak?columns=blob" "73M" +jsonKeyTest "50M" "POST" "/leak?columns=blob" "73M" +jsonKeyTest "50M" "PATCH" "/leak?id=eq.1&columns=blob" "73M" -postJsonArrayTest "1000" "/perf_articles?columns=id,body" "20M" -postJsonArrayTest "10000" "/perf_articles?columns=id,body" "20M" -postJsonArrayTest "100000" "/perf_articles?columns=id,body" "24M" +postJsonArrayTest "1000" "/perf_articles?columns=id,body" "21M" +postJsonArrayTest "10000" "/perf_articles?columns=id,body" "22M" +postJsonArrayTest "100000" "/perf_articles?columns=id,body" "25M" trap - int term exit