From 24683d01616b87ee71fbcf4a33d8957a35b6dfb3 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Sun, 21 Dec 2025 21:02:49 -0500 Subject: [PATCH 1/5] nix: timeout param for withPgrst --- nix/tools/withTools.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index 3417213539..1a6d140534 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -361,6 +361,7 @@ let "ARG_POSITIONAL_SINGLE([command], [Command to run])" "ARG_LEFTOVERS([command arguments])" "ARG_OPTIONAL_SINGLE([monitor], [m], [Enable CPU and memory monitoring of the PostgREST process and output to the designated file as markdown])" + "ARG_OPTIONAL_SINGLE([timeout], [t], [Timeout for the PostgREST process], [5])" "ARG_USE_ENV([PGRST_CMD], [], [PostgREST executable to run])" ]; positionalCompletion = "_command"; @@ -412,7 +413,7 @@ let } trap cleanup EXIT - timeout -s TERM 5 ${waitForPgrstReady} || { + timeout -s TERM "$_arg_timeout" ${waitForPgrstReady} || { echo "timed out, output:" cat "$tmpdir"/run.log exit 1 From a1cdecb224412cd0487752c6fc486154e84b2a0f Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Mon, 22 Dec 2025 19:51:00 -0500 Subject: [PATCH 2/5] nix: show wait time on withPgrst --- nix/tools/withTools.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index 1a6d140534..eddffdd299 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -413,12 +413,14 @@ let } trap cleanup EXIT + wait_start=$SECONDS timeout -s TERM "$_arg_timeout" ${waitForPgrstReady} || { echo "timed out, output:" cat "$tmpdir"/run.log exit 1 } - echo "done." + wait_duration=$((SECONDS - wait_start)) + printf "done in %ss.\n" "$wait_duration" if [[ -n "$_arg_monitor" ]]; then ${monitorPid} "$pid" > "$_arg_monitor" & From 18196d9c2cfaec872dff402b5788afd72eb92cf5 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Tue, 23 Dec 2025 14:11:32 -0500 Subject: [PATCH 3/5] nix: sleep param for withPgrst --- nix/tools/withTools.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index eddffdd299..e61ad5c764 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -361,7 +361,8 @@ let "ARG_POSITIONAL_SINGLE([command], [Command to run])" "ARG_LEFTOVERS([command arguments])" "ARG_OPTIONAL_SINGLE([monitor], [m], [Enable CPU and memory monitoring of the PostgREST process and output to the designated file as markdown])" - "ARG_OPTIONAL_SINGLE([timeout], [t], [Timeout for the PostgREST process], [5])" + "ARG_OPTIONAL_SINGLE([timeout], [t], [Maximum time to wait for PostgREST to be ready], [5])" + "ARG_OPTIONAL_SINGLE([sleep], [s], [Sleep time after PostgREST is ready, this is useful for monitoring], [0])" "ARG_USE_ENV([PGRST_CMD], [], [PostgREST executable to run])" ]; positionalCompletion = "_command"; @@ -426,6 +427,10 @@ let ${monitorPid} "$pid" > "$_arg_monitor" & fi + if [[ -n "$_arg_sleep" ]]; then + sleep "$_arg_sleep" + fi + ("$_arg_command" "''${_arg_leftovers[@]}") ''; From 6d73ed04779985d80119e7b1ba19795f8a509fe2 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Tue, 23 Dec 2025 13:22:22 -0500 Subject: [PATCH 4/5] nix: show wait time for fixture loading --- nix/tools/withTools.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index e61ad5c764..3ab5aa6646 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -132,9 +132,11 @@ let fi if test "$_arg_fixtures"; then - log "Loading fixtures under the postgres role..." + load_start=$SECONDS + >&2 printf "${commandName}: Loading fixtures under the postgres role..." psql -U postgres -v PGUSER="$PGUSER" -v ON_ERROR_STOP=1 -f "$_arg_fixtures" >> "$setuplog" - log "Done. Running command..." + load_end=$((SECONDS - load_start)) + >&2 printf " done in %ss. Running command...\n" "$load_end" fi ("$_arg_command" "''${_arg_leftovers[@]}") From 895518a26cc81026d6df85ce2d121cfba7d2b1c8 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Sun, 21 Dec 2025 22:02:42 -0500 Subject: [PATCH 5/5] nix: add new loadtest for errors Also included it in CI. --- .github/workflows/test.yaml | 2 +- nix/tools/loadtest.nix | 13 +++++++++++-- test/load/errors.http | 15 +++++++++++++++ test/load/errors.sql | 7 +++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 test/load/errors.http create mode 100644 test/load/errors.sql diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index eccfa969a7..67a2505f16 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -120,7 +120,7 @@ jobs: loadtest: strategy: matrix: - kind: ['mixed', 'jwt-hs', 'jwt-hs-cache', 'jwt-hs-cache-worst', 'jwt-rsa', 'jwt-rsa-cache', 'jwt-rsa-cache-worst'] + kind: ['mixed', 'errors', 'jwt-hs', 'jwt-hs-cache', 'jwt-hs-cache-worst', 'jwt-rsa', 'jwt-rsa-cache', 'jwt-rsa-cache-worst'] name: Loadtest runs-on: ubuntu-24.04 steps: diff --git a/nix/tools/loadtest.nix b/nix/tools/loadtest.nix index d669344789..b25c435916 100644 --- a/nix/tools/loadtest.nix +++ b/nix/tools/loadtest.nix @@ -45,7 +45,7 @@ let "ARG_OPTIONAL_SINGLE([testdir], [t], [Directory to load tests and fixtures from], [./test/load])" "ARG_OPTIONAL_SINGLE([kind], [k], [Kind of loadtest], [mixed])" "ARG_OPTIONAL_SINGLE([method],, [HTTP method used for the jwt loadtests], [OPTIONS])" - "ARG_TYPE_GROUP_SET([KIND], [KIND], [kind], [mixed,jwt-hs,jwt-hs-cache,jwt-hs-cache-worst,jwt-rsa,jwt-rsa-cache,jwt-rsa-cache-worst])" + "ARG_TYPE_GROUP_SET([KIND], [KIND], [kind], [mixed,errors,jwt-hs,jwt-hs-cache,jwt-hs-cache-worst,jwt-rsa,jwt-rsa-cache,jwt-rsa-cache-worst])" "ARG_TYPE_GROUP_SET([METHOD], [METHOD], [method], [OPTIONS,GET])" "ARG_OPTIONAL_SINGLE([monitor], [m], [Monitoring file], [./loadtest/result.csv])" "ARG_LEFTOVERS([additional vegeta arguments])" @@ -152,11 +152,20 @@ let sh -c "cd \"$_arg_testdir\" && \ ${runner} -targets targets.http -output \"$abs_output\" \"''${_arg_leftovers[@]}\"" ;; + + # here we sleep purposefully to check how much memory does the schema cache consume in the final report + errors) + # shellcheck disable=SC2145 + ${withTools.withPg} -f "$_arg_testdir"/errors.sql \ + ${withTools.withPgrst} --timeout 2 --sleep 5 -m "$_arg_monitor" \ + sh -c "cd \"$_arg_testdir\" && \ + ${runner} -targets errors.http -output \"$abs_output\" \"''${_arg_leftovers[@]}\"" + ;; esac ${vegeta}/bin/vegeta report -type=text "$_arg_output" - if [ "$_arg_kind" != "mixed" ]; then + if [ "$_arg_kind" != "errors" ]; then # fail in case 401 happened on jwt loadtests unauthorized_count="$(${vegeta}/bin/vegeta report -type=json "$_arg_output" \ | ${jq}/bin/jq -r '.status_codes["401"] // 0')" diff --git a/test/load/errors.http b/test/load/errors.http new file mode 100644 index 0000000000..b72b4354ed --- /dev/null +++ b/test/load/errors.http @@ -0,0 +1,15 @@ +# Misspelled relations +GET http://postgrest/actoxs?actor=eq.1 +Prefer: tx=commit + +# Misspelled relations on embeds +GET http://postgrest/actors?select=*,rolws(*,films(*)) +Prefer: tx=commit + +# Misspelled function names +GET http://postgrest/rpc/call_em_x?name=John +Prefer: tx=commit + +# Permission denied errors +GET http://postgrest/actors_1 +Prefer: tx=commit diff --git a/test/load/errors.sql b/test/load/errors.sql new file mode 100644 index 0000000000..cf70ab7086 --- /dev/null +++ b/test/load/errors.sql @@ -0,0 +1,7 @@ +\ir fixtures.sql + +SELECT format('CREATE TABLE test.actors_%s ();', n) +FROM generate_series(1, 20000) n +\gexec + +-- TODO add many function for fuzzy search (somehow this is making the loadtest start slow)