2022-10-28 21:52:39 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2022-10-31 23:28:21 +03:00
|
|
|
# TODO: use --fail-with-body to get the response body on failure
|
|
|
|
CURL=${CURL:-curl -sSf}
|
2022-10-28 21:52:39 +03:00
|
|
|
DATABASE_URL="${DATABASE_URL:-postgres://postgres@localhost/db}"
|
2022-10-31 23:28:21 +03:00
|
|
|
MARTIN_BUILD="${MARTIN_BUILD:-cargo build}"
|
2022-10-28 21:52:39 +03:00
|
|
|
MARTIN_BIN="${MARTIN_BIN:-cargo run --}"
|
|
|
|
|
|
|
|
function wait_for_martin {
|
|
|
|
# Seems the --retry-all-errors option is not available on older curl versions, but maybe in the future we can just use this:
|
2022-11-26 12:46:40 +03:00
|
|
|
# timeout -k 20s 20s curl --retry 10 --retry-all-errors --retry-delay 1 -sS http://localhost:3000/health
|
2022-11-02 21:00:05 +03:00
|
|
|
PROCESS_ID=$1
|
|
|
|
echo "Waiting for Martin ($PROCESS_ID) to start..."
|
|
|
|
for i in {1..30}; do
|
2022-11-26 12:46:40 +03:00
|
|
|
if curl -sSf http://localhost:3000/health 2>/dev/null >/dev/null; then
|
2022-10-31 23:28:21 +03:00
|
|
|
echo "Martin is up!"
|
2022-11-26 12:46:40 +03:00
|
|
|
curl -s http://localhost:3000/health
|
2022-10-31 23:28:21 +03:00
|
|
|
return
|
|
|
|
fi
|
2022-11-02 21:00:05 +03:00
|
|
|
if ps -p $PROCESS_ID > /dev/null ; then
|
|
|
|
echo "Martin is not up yet, waiting..."
|
|
|
|
sleep 1
|
|
|
|
else
|
|
|
|
echo "Martin died!"
|
|
|
|
ps au
|
|
|
|
lsof -i
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-10-28 21:52:39 +03:00
|
|
|
done
|
2022-10-31 23:28:21 +03:00
|
|
|
echo "Martin did not start in time"
|
|
|
|
ps au
|
|
|
|
lsof -i
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2022-11-02 21:00:05 +03:00
|
|
|
function kill_process {
|
|
|
|
PROCESS_ID=$1
|
|
|
|
echo "Waiting for Martin ($PROCESS_ID) to stop..."
|
|
|
|
kill $PROCESS_ID
|
|
|
|
for i in {1..50}; do
|
|
|
|
if ps -p $PROCESS_ID > /dev/null ; then
|
|
|
|
sleep 0.1
|
|
|
|
else
|
|
|
|
echo "Martin ($PROCESS_ID) has stopped"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Martin did not stop in time, killing it"
|
|
|
|
kill -9 $PROCESS_ID
|
|
|
|
# wait for it to die using timeout and wait
|
|
|
|
timeout -k 1s 1s wait $PROCESS_ID || true
|
|
|
|
}
|
|
|
|
|
2022-10-31 23:28:21 +03:00
|
|
|
test_pbf()
|
|
|
|
{
|
|
|
|
FILENAME="$TEST_OUT_DIR/$1.pbf"
|
|
|
|
URL=$2
|
|
|
|
|
|
|
|
echo "Testing $(basename "$FILENAME") from $URL"
|
|
|
|
$CURL "$URL" > "$FILENAME"
|
|
|
|
|
|
|
|
if [[ $OSTYPE == linux* ]]; then
|
|
|
|
./tests/vtzero-check "$FILENAME"
|
|
|
|
./tests/vtzero-show "$FILENAME" > "$FILENAME.txt"
|
|
|
|
fi
|
2022-10-28 21:52:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
curl --version
|
|
|
|
|
2022-10-31 23:28:21 +03:00
|
|
|
# Make sure martin is built - this way it won't timeout while waiting for it to start
|
|
|
|
# If MARTIN_BUILD is set to "-", don't build
|
|
|
|
if [[ "$MARTIN_BUILD" != "-" ]]; then
|
|
|
|
$MARTIN_BUILD
|
|
|
|
fi
|
|
|
|
|
2022-11-02 21:00:05 +03:00
|
|
|
|
|
|
|
echo "------------------------------------------------------------------------------------------------------------------------"
|
|
|
|
echo "Test auto configured Martin"
|
|
|
|
set -x
|
2022-10-28 21:52:39 +03:00
|
|
|
$MARTIN_BIN --default-srid 900913 &
|
|
|
|
PROCESS_ID=$!
|
2022-11-02 21:00:05 +03:00
|
|
|
{ set +x; } 2> /dev/null
|
|
|
|
trap "kill -9 $PROCESS_ID 2> /dev/null || true" EXIT
|
|
|
|
wait_for_martin $PROCESS_ID
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
TEST_OUT_DIR="$(dirname "$0")/output/auto"
|
|
|
|
mkdir -p "$TEST_OUT_DIR"
|
|
|
|
|
|
|
|
>&2 echo "Test catalog"
|
2022-11-26 12:46:40 +03:00
|
|
|
$CURL http://localhost:3000/catalog | jq --sort-keys -e | tee "$TEST_OUT_DIR/catalog.json"
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
>&2 echo "Test server response for table source"
|
2022-11-26 12:46:40 +03:00
|
|
|
test_pbf tbl_0_0_0 http://localhost:3000/table_source/0/0/0
|
|
|
|
test_pbf tbl_6_38_20 http://localhost:3000/table_source/6/38/20
|
|
|
|
test_pbf tbl_12_2476_1280 http://localhost:3000/table_source/12/2476/1280
|
|
|
|
test_pbf tbl_13_4952_2560 http://localhost:3000/table_source/13/4952/2560
|
|
|
|
test_pbf tbl_14_9904_5121 http://localhost:3000/table_source/14/9904/5121
|
|
|
|
test_pbf tbl_20_633856_327787 http://localhost:3000/table_source/20/633856/327787
|
|
|
|
test_pbf tbl_21_1267712_655574 http://localhost:3000/table_source/21/1267712/655574
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
>&2 echo "Test server response for composite source"
|
2022-11-26 12:46:40 +03:00
|
|
|
test_pbf cmp_0_0_0 http://localhost:3000/table_source,points1,points2/0/0/0
|
|
|
|
test_pbf cmp_6_38_20 http://localhost:3000/table_source,points1,points2/6/38/20
|
|
|
|
test_pbf cmp_12_2476_1280 http://localhost:3000/table_source,points1,points2/12/2476/1280
|
|
|
|
test_pbf cmp_13_4952_2560 http://localhost:3000/table_source,points1,points2/13/4952/2560
|
|
|
|
test_pbf cmp_14_9904_5121 http://localhost:3000/table_source,points1,points2/14/9904/5121
|
|
|
|
test_pbf cmp_20_633856_327787 http://localhost:3000/table_source,points1,points2/20/633856/327787
|
|
|
|
test_pbf cmp_21_1267712_655574 http://localhost:3000/table_source,points1,points2/21/1267712/655574
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
>&2 echo "Test server response for function source"
|
2022-11-30 19:57:27 +03:00
|
|
|
test_pbf fnc_0_0_0 http://localhost:3000/function_zxy_query/0/0/0
|
|
|
|
test_pbf fnc_6_38_20 http://localhost:3000/function_zxy_query/6/38/20
|
|
|
|
test_pbf fnc_12_2476_1280 http://localhost:3000/function_zxy_query/12/2476/1280
|
|
|
|
test_pbf fnc_13_4952_2560 http://localhost:3000/function_zxy_query/13/4952/2560
|
|
|
|
test_pbf fnc_14_9904_5121 http://localhost:3000/function_zxy_query/14/9904/5121
|
|
|
|
test_pbf fnc_20_633856_327787 http://localhost:3000/function_zxy_query/20/633856/327787
|
|
|
|
test_pbf fnc_21_1267712_655574 http://localhost:3000/function_zxy_query/21/1267712/655574
|
|
|
|
test_pbf fnc_0_0_0_token http://localhost:3000/function_zxy_query_test/0/0/0?token=martin
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
>&2 echo "Test server response for table source with different SRID"
|
2022-11-26 12:46:40 +03:00
|
|
|
test_pbf points3857_srid_0_0_0 http://localhost:3000/points3857/0/0/0
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
>&2 echo "Test server response for table source with empty SRID"
|
|
|
|
echo "IGNORING: This test is currently failing, and has been failing for a while"
|
2022-11-26 12:46:40 +03:00
|
|
|
echo "IGNORING: " test_pbf points_empty_srid_0_0_0 http://localhost:3000/points_empty_srid/0/0/0
|
2022-10-31 23:28:21 +03:00
|
|
|
|
2022-11-02 21:00:05 +03:00
|
|
|
kill_process $PROCESS_ID
|
2022-10-28 21:52:39 +03:00
|
|
|
|
2022-10-31 23:28:21 +03:00
|
|
|
|
2022-11-02 21:00:05 +03:00
|
|
|
echo "------------------------------------------------------------------------------------------------------------------------"
|
|
|
|
echo "Test pre-configured Martin"
|
|
|
|
set -x
|
2022-10-28 21:52:39 +03:00
|
|
|
$MARTIN_BIN --config tests/config.yaml "$DATABASE_URL" &
|
|
|
|
PROCESS_ID=$!
|
2022-11-02 21:00:05 +03:00
|
|
|
{ set +x; } 2> /dev/null
|
|
|
|
trap "kill -9 $PROCESS_ID 2> /dev/null || true" EXIT
|
|
|
|
wait_for_martin $PROCESS_ID
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
TEST_OUT_DIR="$(dirname "$0")/output/configured"
|
|
|
|
mkdir -p "$TEST_OUT_DIR"
|
|
|
|
|
|
|
|
>&2 echo "Test catalog"
|
2022-11-26 12:46:40 +03:00
|
|
|
$CURL http://localhost:3000/catalog | jq --sort-keys -e | tee "$TEST_OUT_DIR/catalog.json"
|
2022-10-31 23:28:21 +03:00
|
|
|
|
2022-11-26 12:46:40 +03:00
|
|
|
test_pbf tbl_0_0_0 http://localhost:3000/table_source/0/0/0
|
|
|
|
test_pbf cmp_0_0_0 http://localhost:3000/points1,points2/0/0/0
|
2022-11-30 19:57:27 +03:00
|
|
|
test_pbf fnc_0_0_0 http://localhost:3000/function_zxy_query/0/0/0
|
|
|
|
test_pbf fnc2_0_0_0 http://localhost:3000/function_zxy_query_test/0/0/0?token=martin
|
2022-10-31 23:28:21 +03:00
|
|
|
|
2022-11-02 21:00:05 +03:00
|
|
|
kill_process $PROCESS_ID
|
2022-11-30 19:57:27 +03:00
|
|
|
|
|
|
|
>&2 echo "All integration tests have passed"
|