dev: improve postgrest-watch experience
* speed up io tests * avoid infinite loop while watching io tests * improve auto-complete with postgrest-watch postgrest-run * detect when files are added or deleted
This commit is contained in:
committed by
Wolfgang Walther
parent
7d6d015822
commit
d218a9eaff
+3
-1
@@ -14,7 +14,9 @@ let
|
||||
''
|
||||
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
||||
|
||||
${silver-searcher}/bin/ag -l . "$rootdir" | ${entr}/bin/entr -r "$@"
|
||||
while true; do
|
||||
(! ${silver-searcher}/bin/ag -l . "$rootdir" | ${entr}/bin/entr -dr "$@")
|
||||
done
|
||||
'';
|
||||
|
||||
pushCachix =
|
||||
|
||||
+4
-2
@@ -16,7 +16,8 @@ let
|
||||
${nixpkgs-fmt}/bin/nixpkgs-fmt "$rootdir" > /dev/null 2> /dev/null
|
||||
|
||||
# Format Haskell files
|
||||
${silver-searcher}/bin/ag -l -g '\.l?hs$' . "$rootdir" \
|
||||
# --vimgrep fixes a bug in ag: https://github.com/ggreer/the_silver_searcher/issues/753
|
||||
${silver-searcher}/bin/ag -l --vimgrep -g '\.l?hs$' . "$rootdir" \
|
||||
| xargs ${stylish-haskell}/bin/stylish-haskell -i
|
||||
'';
|
||||
|
||||
@@ -35,7 +36,8 @@ let
|
||||
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
||||
|
||||
# Lint Haskell files
|
||||
${silver-searcher}/bin/ag -l -g '\.l?hs$' "$rootdir" \
|
||||
# --vimgrep fixes a bug in ag: https://github.com/ggreer/the_silver_searcher/issues/753
|
||||
${silver-searcher}/bin/ag -l --vimgrep -g '\.l?hs$' "$rootdir" \
|
||||
| xargs ${hlint}/bin/hlint -X QuasiQuotes -X NoPatternSynonyms
|
||||
'';
|
||||
in
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@
|
||||
, postgrest
|
||||
, postgrestStatic
|
||||
, postgrestProfiled
|
||||
, procps
|
||||
, runtimeShell
|
||||
}:
|
||||
let
|
||||
@@ -78,7 +79,7 @@ let
|
||||
name
|
||||
''
|
||||
env="$(cat ${postgrest.env})"
|
||||
export PATH="$env/bin:${curl}/bin:$PATH"
|
||||
export PATH="$env/bin:${curl}/bin:${procps}/bin:$PATH"
|
||||
|
||||
rootdir="$(${git}/bin/git rev-parse --show-toplevel)"
|
||||
cd "$rootdir"
|
||||
|
||||
@@ -38,7 +38,8 @@ lib.overrideDerivation postgrest.env (
|
||||
|
||||
shellHook =
|
||||
''
|
||||
complete -c postgrest-watch
|
||||
source ${pkgs.bashCompletion}/etc/profile.d/bash_completion.sh
|
||||
complete -F _command postgrest-watch
|
||||
'';
|
||||
}
|
||||
)
|
||||
|
||||
+28
-34
@@ -88,8 +88,7 @@ readSecretFromFile(){
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
if pgrStarted
|
||||
then
|
||||
@@ -113,8 +112,7 @@ readDbUriFromStdin(){
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
if pgrStarted
|
||||
then
|
||||
@@ -131,8 +129,7 @@ reqWithRoleClaimKey(){
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
authorsJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign('$2', 'reallyreallyreallyreallyverysafe');")
|
||||
httpStatus="$( authorsStatus "$authorsJwt" )"
|
||||
@@ -151,8 +148,7 @@ invalidRoleClaimKey(){
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
if pgrStarted
|
||||
then
|
||||
@@ -169,8 +165,7 @@ ensureIatClaimWorks(){
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
for i in {1..10}; do \
|
||||
iatJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign(row_to_json(r), 'reallyreallyreallyreallyverysafe') from ( select 'postgrest_test_author' as role, extract(epoch from now()) as iat) r")
|
||||
@@ -186,16 +181,16 @@ ensureIatClaimWorks(){
|
||||
pgrStop
|
||||
}
|
||||
|
||||
# ensure app settings don't reset on pool timeout of 10 seconds, see https://github.com/PostgREST/postgrest/issues/1141
|
||||
# ensure app settings don't reset on pool timeout, see https://github.com/PostgREST/postgrest/issues/1141
|
||||
# pool timeout set to 1s to shorten runtime
|
||||
ensureAppSettings(){
|
||||
pgrStart "./configs/app-settings.config"
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
sleep 11
|
||||
sleep 2
|
||||
response=$(curl -s "http://localhost:$pgrPort/rpc/get_guc_value?name=app.settings.external_api_secret")
|
||||
if test "$response" = "\"0123456789abcdef\""
|
||||
then
|
||||
@@ -207,15 +202,17 @@ ensureAppSettings(){
|
||||
}
|
||||
|
||||
checkAppSettingsReload(){
|
||||
pgrStart "./configs/sigusr2-settings.config"
|
||||
configFile=$(mktemp)
|
||||
trap "rm -f $configFile" ERR RETURN
|
||||
cat "./configs/sigusr2-settings.config" > "$configFile"
|
||||
pgrStart "$configFile"
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
# change setting
|
||||
replaceConfigValue "app.settings.name_var" "Jane" ./configs/sigusr2-settings.config
|
||||
replaceConfigValue "app.settings.name_var" "Jane" "$configFile"
|
||||
# reload
|
||||
kill -s SIGUSR2 $pgrPID
|
||||
response=$(curl -s "http://localhost:$pgrPort/rpc/get_guc_value?name=app.settings.name_var")
|
||||
@@ -226,21 +223,21 @@ checkAppSettingsReload(){
|
||||
ko "app.settings.name_var config not reloaded with SIGUSR2. Got: $response"
|
||||
fi
|
||||
pgrStop
|
||||
# go back to original setting
|
||||
replaceConfigValue "app.settings.name_var" "John" ./configs/sigusr2-settings.config
|
||||
}
|
||||
|
||||
checkJwtSecretReload(){
|
||||
pgrStart "./configs/sigusr2-settings.config"
|
||||
configFile=$(mktemp)
|
||||
trap "rm -f $configFile" ERR RETURN
|
||||
cat "./configs/sigusr2-settings.config" > "$configFile"
|
||||
pgrStart "$configFile"
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
secret="reallyreallyreallyreallyverysafe"
|
||||
# change setting
|
||||
replaceConfigValue "jwt-secret" "$secret" ./configs/sigusr2-settings.config
|
||||
replaceConfigValue "jwt-secret" "$secret" "$configFile"
|
||||
# reload
|
||||
kill -s SIGUSR2 $pgrPID
|
||||
payload='{"role":"postgrest_test_author"}'
|
||||
@@ -253,20 +250,20 @@ checkJwtSecretReload(){
|
||||
ko "jwt-secret config not reloaded with SIGUSR2. Got: $httpStatus"
|
||||
fi
|
||||
pgrStop
|
||||
# go back to original setting
|
||||
replaceConfigValue "jwt-secret" "invalidinvalidinvalidinvalidinvalid" ./configs/sigusr2-settings.config
|
||||
}
|
||||
|
||||
checkDbSchemaReload(){
|
||||
pgrStart "./configs/sigusr2-settings.config"
|
||||
configFile=$(mktemp)
|
||||
trap "rm -f $configFile" ERR RETURN
|
||||
cat "./configs/sigusr2-settings.config" > "$configFile"
|
||||
pgrStart "$configFile"
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
# add v1 schema to db-schema
|
||||
replaceConfigValue "db-schema" "test, v1" ./configs/sigusr2-settings.config
|
||||
replaceConfigValue "db-schema" "test, v1" "$configFile"
|
||||
# reload
|
||||
kill -s SIGUSR2 $pgrPID
|
||||
kill -s SIGUSR1 $pgrPID
|
||||
@@ -278,8 +275,6 @@ checkDbSchemaReload(){
|
||||
ko "db-schema config not reloaded with SIGUSR2. Got: $httpStatus"
|
||||
fi
|
||||
pgrStop
|
||||
# go back to original setting
|
||||
replaceConfigValue "db-schema" "test" ./configs/sigusr2-settings.config
|
||||
}
|
||||
|
||||
replaceConfigValue(){
|
||||
@@ -295,8 +290,7 @@ socketConnection(){
|
||||
while pgrStarted && test "$( getSocketStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
sleep 0.1
|
||||
done
|
||||
if test $( getSocketStatus ) -eq 200
|
||||
then
|
||||
|
||||
@@ -2,6 +2,7 @@ db-uri = "$(POSTGREST_TEST_CONNECTION)"
|
||||
db-schema = "test"
|
||||
db-anon-role = "postgrest_test_anonymous"
|
||||
db-pool = 1
|
||||
db-pool-timeout = 1
|
||||
server-host = "127.0.0.1"
|
||||
server-port = 49421
|
||||
|
||||
|
||||
Reference in New Issue
Block a user