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}"
|
2023-01-01 08:03:21 +03:00
|
|
|
MARTIN_BUILD="${MARTIN_BUILD:-cargo build --all-features}"
|
|
|
|
MARTIN_PORT="${MARTIN_PORT:-3111}"
|
2022-12-19 05:24:06 +03:00
|
|
|
MARTIN_URL="http://localhost:${MARTIN_PORT}"
|
2023-01-01 08:03:21 +03:00
|
|
|
MARTIN_ARGS="${MARTIN_ARGS:---listen-addresses localhost:${MARTIN_PORT}}"
|
|
|
|
MARTIN_BIN="${MARTIN_BIN:-cargo run --all-features --} ${MARTIN_ARGS}"
|
2022-10-28 21:52:39 +03:00
|
|
|
|
|
|
|
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-12-19 05:24:06 +03:00
|
|
|
# timeout -k 20s 20s curl --retry 10 --retry-all-errors --retry-delay 1 -sS "$MARTIN_URL/health"
|
2022-11-02 21:00:05 +03:00
|
|
|
PROCESS_ID=$1
|
2022-12-27 09:56:27 +03:00
|
|
|
echo "Waiting for Martin ($PROCESS_ID) to start by checking $MARTIN_URL/health to be valid..."
|
|
|
|
for i in {1..60}; do
|
2022-12-19 05:24:06 +03:00
|
|
|
if curl -sSf "$MARTIN_URL/health" 2>/dev/null >/dev/null; then
|
2022-10-31 23:28:21 +03:00
|
|
|
echo "Martin is up!"
|
2022-12-19 05:24:06 +03:00
|
|
|
curl -s "$MARTIN_URL/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
|
2022-12-27 09:56:27 +03:00
|
|
|
echo "Martin is not up yet, waiting for $MARTIN_URL/health ..."
|
2022-11-02 21:00:05 +03:00
|
|
|
sleep 1
|
|
|
|
else
|
|
|
|
echo "Martin died!"
|
|
|
|
ps au
|
2022-12-12 17:11:10 +03:00
|
|
|
lsof -i || true
|
2022-11-02 21:00:05 +03:00
|
|
|
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
|
2022-12-12 17:11:10 +03:00
|
|
|
lsof -i || true
|
2022-10-31 23:28:21 +03:00
|
|
|
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"
|
2022-12-19 05:24:06 +03:00
|
|
|
URL="$MARTIN_URL/$2"
|
2022-10-31 23:28:21 +03:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-01 08:03:21 +03:00
|
|
|
clean_yaml()
|
|
|
|
{
|
|
|
|
YAML_FILE="$1"
|
|
|
|
>&2 echo "Cleaning up yaml file $YAML_FILE"
|
|
|
|
# sed -i "/ connection_string: .*/d" "${YAML_FILE}"
|
|
|
|
grep -v " connection_string: " "${YAML_FILE}" > "${YAML_FILE}.tmp"
|
|
|
|
mv "${YAML_FILE}.tmp" "${YAML_FILE}"
|
|
|
|
}
|
|
|
|
|
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"
|
2022-12-12 17:11:10 +03:00
|
|
|
|
2022-12-27 09:56:27 +03:00
|
|
|
TEST_OUT_DIR="$(dirname "$0")/output/auto"
|
|
|
|
mkdir -p "$TEST_OUT_DIR"
|
|
|
|
|
|
|
|
ARG=(--default-srid 900913 --save-config "$(dirname "$0")/output/generated_config.yaml")
|
|
|
|
set -x
|
2022-12-12 17:11:10 +03:00
|
|
|
$MARTIN_BIN "${ARG[@]}" 2>&1 | tee test_log_1.txt &
|
|
|
|
PROCESS_ID=`jobs -p`
|
|
|
|
|
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
|
|
|
|
|
|
|
>&2 echo "Test catalog"
|
2022-12-27 09:56:27 +03:00
|
|
|
$CURL "$MARTIN_URL/catalog" | jq --sort-keys -e | tee "$TEST_OUT_DIR/catalog_auto.json"
|
2022-10-31 23:28:21 +03:00
|
|
|
|
2022-12-27 09:56:27 +03:00
|
|
|
>&2 echo "***** Test server response for table source *****"
|
2022-12-19 05:24:06 +03:00
|
|
|
test_pbf tbl_0_0_0 table_source/0/0/0
|
2022-12-27 09:56:27 +03:00
|
|
|
test_pbf tbl_6_57_29 table_source/6/57/29
|
|
|
|
test_pbf tbl_12_3673_1911 table_source/12/3673/1911
|
|
|
|
test_pbf tbl_13_7346_3822 table_source/13/7346/3822
|
|
|
|
test_pbf tbl_14_14692_7645 table_source/14/14692/7645
|
|
|
|
test_pbf tbl_17_117542_61161 table_source/17/117542/61161
|
|
|
|
test_pbf tbl_18_235085_122323 table_source/18/235085/122323
|
|
|
|
|
|
|
|
>&2 echo "***** Test server response for composite source *****"
|
2022-12-19 05:24:06 +03:00
|
|
|
test_pbf cmp_0_0_0 table_source,points1,points2/0/0/0
|
2022-12-27 09:56:27 +03:00
|
|
|
test_pbf cmp_6_57_29 table_source,points1,points2/6/57/29
|
|
|
|
test_pbf cmp_12_3673_1911 table_source,points1,points2/12/3673/1911
|
|
|
|
test_pbf cmp_13_7346_3822 table_source,points1,points2/13/7346/3822
|
|
|
|
test_pbf cmp_14_14692_7645 table_source,points1,points2/14/14692/7645
|
|
|
|
test_pbf cmp_17_117542_61161 table_source,points1,points2/17/117542/61161
|
|
|
|
test_pbf cmp_18_235085_122323 table_source,points1,points2/18/235085/122323
|
|
|
|
|
|
|
|
>&2 echo "***** Test server response for function source *****"
|
2022-12-19 05:24:06 +03:00
|
|
|
test_pbf fnc_0_0_0 function_zxy_query/0/0/0
|
2022-12-27 09:56:27 +03:00
|
|
|
test_pbf fnc_6_57_29 function_zxy_query/6/57/29
|
|
|
|
test_pbf fnc_12_3673_1911 function_zxy_query/12/3673/1911
|
|
|
|
test_pbf fnc_13_7346_3822 function_zxy_query/13/7346/3822
|
|
|
|
test_pbf fnc_14_14692_7645 function_zxy_query/14/14692/7645
|
|
|
|
test_pbf fnc_17_117542_61161 function_zxy_query/17/117542/61161
|
|
|
|
test_pbf fnc_18_235085_122323 function_zxy_query/18/235085/122323
|
2022-12-19 05:24:06 +03:00
|
|
|
test_pbf fnc_0_0_0_token function_zxy_query_test/0/0/0?token=martin
|
2022-12-27 09:56:27 +03:00
|
|
|
test_pbf fnc_b_6_38_20 function_zxy_query_jsonb/6/57/29
|
|
|
|
|
|
|
|
>&2 echo "***** Test server response for different function call types *****"
|
|
|
|
test_pbf fnc_zoom_xy_6_57_29 function_zoom_xy/6/57/29
|
|
|
|
test_pbf fnc_zxy_6_57_29 function_zxy/6/57/29
|
|
|
|
test_pbf fnc_zxy2_6_57_29 function_zxy2/6/57/29
|
|
|
|
test_pbf fnc_zxy_query_6_57_29 function_zxy_query/6/57/29
|
|
|
|
test_pbf fnc_zxy_row_6_57_29 function_zxy_row/6/57/29
|
|
|
|
test_pbf fnc_zxy_row2_6_57_29 function_Mixed_Name/6/57/29
|
|
|
|
test_pbf fnc_zxy_row_key_6_57_29 function_zxy_row_key/6/57/29
|
|
|
|
|
|
|
|
>&2 echo "***** Test server response for table source with different SRID *****"
|
2022-12-19 05:24:06 +03:00
|
|
|
test_pbf points3857_srid_0_0_0 points3857/0/0/0
|
2022-10-31 23:28:21 +03:00
|
|
|
|
2022-12-27 09:56:27 +03:00
|
|
|
>&2 echo "***** Test server response for table source with empty SRID *****"
|
2022-10-31 23:28:21 +03:00
|
|
|
echo "IGNORING: This test is currently failing, and has been failing for a while"
|
2022-12-19 05:24:06 +03:00
|
|
|
echo "IGNORING: " test_pbf points_empty_srid_0_0_0 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
|
2023-01-01 08:03:21 +03:00
|
|
|
(cat test_log_1.txt | grep -v 'Margin parameter in ST_TileEnvelope is not supported' | grep -e ' ERROR ' -e ' WARN ') && exit 1
|
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"
|
2022-12-27 09:56:27 +03:00
|
|
|
TEST_OUT_DIR="$(dirname "$0")/output/configured"
|
|
|
|
mkdir -p "$TEST_OUT_DIR"
|
2022-12-12 17:11:10 +03:00
|
|
|
|
2022-12-27 09:56:27 +03:00
|
|
|
ARG=(--config tests/config.yaml --save-config "$(dirname "$0")/output/given_config.yaml" -W 1)
|
|
|
|
set -x
|
2022-12-12 17:11:10 +03:00
|
|
|
$MARTIN_BIN "${ARG[@]}" 2>&1 | tee test_log_2.txt &
|
|
|
|
PROCESS_ID=`jobs -p`
|
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
|
|
|
|
|
|
|
>&2 echo "Test catalog"
|
2022-12-27 09:56:27 +03:00
|
|
|
$CURL "$MARTIN_URL/catalog" | jq --sort-keys -e | tee "$TEST_OUT_DIR/catalog_cfg.json"
|
2022-10-31 23:28:21 +03:00
|
|
|
|
2022-12-19 05:24:06 +03:00
|
|
|
test_pbf tbl_0_0_0 table_source/0/0/0
|
|
|
|
test_pbf cmp_0_0_0 points1,points2/0/0/0
|
|
|
|
test_pbf fnc_0_0_0 function_zxy_query/0/0/0
|
|
|
|
test_pbf fnc2_0_0_0 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
|
2023-01-01 08:03:21 +03:00
|
|
|
(cat test_log_2.txt | grep -v 'Margin parameter in ST_TileEnvelope is not supported' | grep -e ' ERROR ' -e ' WARN ') && exit 1
|
|
|
|
|
|
|
|
clean_yaml "$(dirname "$0")/output/given_config.yaml"
|
|
|
|
clean_yaml "$(dirname "$0")/output/generated_config.yaml"
|
2022-11-30 19:57:27 +03:00
|
|
|
|
|
|
|
>&2 echo "All integration tests have passed"
|