Nixify io and memory tests (#1538)

* Include tests for io and memory in the Nix environment.
* include spec tests in nix-shell by default
* install the io and memory tests in CI
This commit is contained in:
Remo Rechkemmer
2020-05-28 12:45:14 -05:00
committed by GitHub
parent 784ebe57d7
commit 69b09e312a
18 changed files with 211 additions and 108 deletions
+1
View File
@@ -50,6 +50,7 @@ main = do
cost <- exec pool [str| [{"id": 1}, {"id": 4}] |] $
requestToCallProcQuery (QualifiedIdentifier "test" "get_projects_below") [PgArg "id" "int" True] False (Just MultipleObjects) []
liftIO $ do
-- lower bound needed for now to make sure that cost is not Nothing
cost `shouldSatisfy` (> Just 2000)
cost `shouldSatisfy` (< Just 2100)
+27 -23
View File
@@ -1,7 +1,10 @@
#!/bin/sh
#!/usr/bin/env bash
# Run unit tests for Input/Ouput of PostgREST seen as a black box
# with test output in Test Anything Protocol format.
#
# These tests expect that `postgrest` is on the PATH, as well as `curl` and
# `ncat` (from the nmap package in some distribution).
#
# References:
# [1] Test Anything Protocol
# https://testanything.org/
@@ -12,9 +15,15 @@
# [3] List of TCP and UDP port numbers
# https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
#
set -eu
export POSTGREST_TEST_CONNECTION=${POSTGREST_TEST_CONNECTION:-"postgres:///postgrest_test"}
cd "$(dirname "$0")"
cd io-tests
trap "kill 0" int term exit
# Port for Test PostgREST Server (must match config)
pgrPort=49421 # in range 4915265535: for private or temporary use
@@ -30,11 +39,11 @@ ko(){ result 'not ok' "- $1"; failedTests=$(( $failedTests + 1 )); }
comment(){ echo "# $1"; }
# Utilities to start/stop test PostgREST server running in the background
pgrStart(){ stack exec -- postgrest "$1" >/dev/null & pgrPID="$!"; }
pgrStartRead(){ stack exec -- postgrest "$1" >/dev/null < "$2" & pgrPID="$!"; }
pgrStart(){ postgrest $1 >/dev/null 2>/dev/null & pgrPID="$!"; }
pgrStartRead(){ postgrest $1 <$2 >/dev/null & pgrPID="$!"; }
pgrStartStdin(){ postgrest $1 >/dev/null <<< "$2" & pgrPID="$!"; }
pgrStarted(){ kill -0 "$pgrPID" 2>/dev/null; }
pgrStop(){ kill "$pgrPID" 2>/dev/null; }
pgrStopAll(){ pkill -f "$(stack path --local-install-root)/bin/postgrest"; }
pgrStop(){ kill "$pgrPID" 2>/dev/null; pgrPID=""; }
# Utilities to send HTTP requests to the PostgREST server
rootStatus(){
@@ -47,10 +56,6 @@ authorsStatus(){
"http://localhost:$pgrPort/authors_only"
}
# Start and End of Unit Tests
setUp(){ pgrStopAll; }
cleanUp(){ pgrStopAll; }
# Unit Test Templates
readSecretFromFile(){
case "$1" in
@@ -82,9 +87,9 @@ readSecretFromFile(){
pgrStop
}
readDbUriFromFile(){
readDbUriFromStdin(){
pgrConfig="dburi-from-file.config"
pgrStartRead "./configs/$pgrConfig" "./dburis/$1"
pgrStartStdin "./configs/$pgrConfig" "$1"
while pgrStarted && test "$( rootStatus )" -ne 200
do
# wait for the server to start
@@ -93,9 +98,9 @@ readDbUriFromFile(){
done
if pgrStarted
then
ok "connection with $2 dburi read from a file"
ok "connection with $2 dburi read from stdin / a file"
else
ko "connection with $2 dburi read from a file"
ko "connection with $2 dburi read from stdin / a file"
fi
pgrStop
}
@@ -109,7 +114,7 @@ reqWithRoleClaimKey(){
sleep 0.1 \
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
done
authorsJwt=$(psql -qtAX postgrest_test -c "select jwt.sign('$2', 'reallyreallyreallyreallyverysafe');")
authorsJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign('$2', 'reallyreallyreallyreallyverysafe');")
httpStatus="$( authorsStatus "$authorsJwt" )"
if test "$httpStatus" -eq $3
then
@@ -132,10 +137,10 @@ invalidRoleClaimKey(){
if pgrStarted
then
ko "invalid jspath \"$1\": accepted"
pgrStop
else
ok "invalid jspath \"$1\": rejected"
fi
pgrStop
}
# ensure iat claim is successful in the presence of pgrst time cache, see https://github.com/PostgREST/postgrest/issues/1139
@@ -148,7 +153,7 @@ ensureIatClaimWorks(){
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
done
for i in {1..10}; do \
iatJwt=$(psql -qtAX postgrest_test -c "select jwt.sign(row_to_json(r), 'reallyreallyreallyreallyverysafe') from ( select 'postgrest_test_author' as role, extract(epoch from now()) as iat) r")
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")
httpStatus="$( authorsStatus $iatJwt )"
if test "$httpStatus" -ne 200
then
@@ -209,9 +214,7 @@ socketConnection(){
test -n "$(command -v curl)" || bailOut 'curl is not available'
# PRE: postgres must be running
psql -l 1>/dev/null 2>/dev/null || bailOut 'postgres is not running'
setUp
psql -l "$POSTGREST_TEST_CONNECTION" 1>/dev/null 2>/dev/null || bailOut 'postgres is not running'
echo "Running IO tests.."
@@ -231,8 +234,10 @@ readSecretFromFile ascii.b64 'Base64 (ASCII)'
readSecretFromFile utf8.b64 'Base64 (UTF-8)'
readSecretFromFile binary.b64 'Base64 (binary)'
readDbUriFromFile uri.noeol "(no EOL)"
readDbUriFromFile uri.txt "(EOL)"
eol=$'\x0a'
readDbUriFromStdin "$POSTGREST_TEST_CONNECTION" "(no EOL)"
readDbUriFromStdin "$POSTGREST_TEST_CONNECTION$eol" "(EOL)"
reqWithRoleClaimKey '.postgrest.a_role' '{"postgrest":{"a_role":"postgrest_test_author"}}' 200
reqWithRoleClaimKey '.customObject.manyRoles[1]' '{"customObject":{"manyRoles": ["other", "postgrest_test_author"]}}' 200
@@ -250,7 +255,6 @@ invalidRoleClaimKey 1234
ensureIatClaimWorks
ensureAppSettings
cleanUp
trap - int term exit
exit $failedTests
+1 -1
View File
@@ -1,4 +1,4 @@
db-uri = "postgres:///postgrest_test"
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
@@ -1,4 +1,4 @@
db-uri = "postgres:///postgrest_test"
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
+1 -1
View File
@@ -1,4 +1,4 @@
db-uri = "postgres:///postgrest_test"
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
@@ -1,4 +1,4 @@
db-uri = "postgres:///postgrest_test"
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
+1 -1
View File
@@ -1,4 +1,4 @@
db-uri = "postgres:///postgrest_test"
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
+1 -1
View File
@@ -1,4 +1,4 @@
db-uri = "postgres:///postgrest_test"
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1
-1
View File
@@ -1 +0,0 @@
postgres:///postgrest_test
-1
View File
@@ -1 +0,0 @@
postgres:///postgrest_test
+13 -9
View File
@@ -1,4 +1,15 @@
#! /usr/bin/env bash
# This test script expects that a `postgrest` executable with profiling enabled
# is on the PATH. With stack, for example, you can run `stack install --profile
# postgrest`.
set -eu
export POSTGREST_TEST_CONNECTION=${POSTGREST_TEST_CONNECTION:-"postgres:///postgrest_test"}
trap "kill 0" int term exit
currentTest=1
failedTests=0
result(){ echo "$1 $currentTest $2"; currentTest=$(( $currentTest + 1 )); }
@@ -7,14 +18,9 @@ ko(){ result 'not ok' "- $1"; failedTests=$(( $failedTests + 1 )); }
pgrPort=49421
pgrStopAll(){ pkill -f "$(stack path --profile --local-install-root)/bin/postgrest"; }
pgrStart(){ stack exec --profile -- postgrest test/memory-tests/config +RTS -p -h >/dev/null & pgrPID="$!"; }
pgrStart(){ postgrest test/memory-tests/config +RTS -p -h > /dev/null & pgrPID="$!"; }
pgrStop(){ kill "$pgrPID" 2>/dev/null; }
setUp(){ pgrStopAll; }
cleanUp(){ pgrStopAll; }
checkPgrStarted(){
while pgrStarted && test $(rootStatus) -ne 200
do
@@ -90,8 +96,6 @@ postJsonArrayTest(){
fi
}
setUp
echo "Running memory usage tests.."
jsonKeyTest "1M" "POST" "/rpc/leak?columns=blob" "13M"
@@ -110,6 +114,6 @@ postJsonArrayTest "1000" "/perf_articles?columns=id,body" "11M"
postJsonArrayTest "10000" "/perf_articles?columns=id,body" "11M"
postJsonArrayTest "100000" "/perf_articles?columns=id,body" "21M"
cleanUp
trap - int term exit
exit $failedTests
+1 -1
View File
@@ -1,4 +1,4 @@
db-uri = "postgres:///postgrest_test"
db-uri = "$(POSTGREST_TEST_CONNECTION)"
db-schema = "test"
db-anon-role = "postgrest_test_anonymous"
db-pool = 1