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
|
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"
|
|
|
|
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-12-12 17:11:10 +03:00
|
|
|
|
|
|
|
ARG=(--default-srid 900913)
|
|
|
|
$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
|
|
|
|
|
|
|
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
|
|
|
|
Support z,x,y and record-returning funcs, table rework (#380)
Can now handle several additional Postgres functions to get a tile, plus
tons of small fixes
### Multiple result variants
* `getmvt(z,x,y) -> [bytea,md5]` (single row with two columns)
* `getmvt(z,x,y) -> [bytea]` (single row with a single column)
* `getmvt(z,x,y) -> bytea` (value)
### Multiple input parameter variants
* `getmvt(z, x, y)` or `getmvt(zoom, x, y)` (all 3 vars must be
integers)
* `getmvt(z, x, y, url_query)`, where instead of `url_query` it could be
any other name, but must be of type JSON
### Breaking
* srid is now the same type as PG -- `i32`
* renamed config vals `table_sources` and `function_sources` into
`tables` and `functions`
### Features and fixes
* if postgis is v3.1+, uses margin parameter to extend the search box by
the size of the buffer. I think we should make 3.1 minimal required.
* fixes feature ID issue from #466
* fixes mixed case names for schemas, tables and columns, functions and
parameter names per #389
### Notes
* More dynamic SQL generation in code instead of using external SQL
files. Those should only be used when they are not parametrized.
* The new function/table discovery mechanism: query for all functions in
the database, and match up those functions with the ones configured (if
any), plus adds all the rest of the un-declared ones if discovery mode
is on.
* During table and function discovery, the code generates a map of
`(PgSqlInfo, FunctionInfo)` (or table) tupples containing SQL needed to
get the tile.
* Auto-discovery mode is currently hidden - the discovery is on only
when no tables or functions are configured. TBD - how to configure it in
the future
* The new system allows for an easy way to auto-discover for the
specific schemas only, solving #47
* predictable order of table/function instantiation
* bounding boxes computed in parallel for all tables (when not
configured)
* proper identifier escaping
* test cleanup
fixes #378
fixes #466
fixes #65
fixes #389
2022-12-10 17:20:42 +03:00
|
|
|
>&2 echo "Test server response for different function call types"
|
|
|
|
test_pbf fnc_zoom_xy_6_38_20 http://localhost:3000/function_zoom_xy/6/38/20
|
|
|
|
test_pbf fnc_zxy_6_38_20 http://localhost:3000/function_zxy/6/38/20
|
|
|
|
test_pbf fnc_zxy2_6_38_20 http://localhost:3000/function_zxy2/6/38/20
|
|
|
|
test_pbf fnc_zxy_query_6_38_20 http://localhost:3000/function_zxy_query/6/38/20
|
|
|
|
test_pbf fnc_zxy_row_6_38_20 http://localhost:3000/function_zxy_row/6/38/20
|
|
|
|
test_pbf fnc_zxy_row2_6_38_20 http://localhost:3000/function_Mixed_Name/6/38/20
|
|
|
|
test_pbf fnc_zxy_row_key_6_38_20 http://localhost:3000/function_zxy_row_key/6/38/20
|
|
|
|
|
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-12-12 17:11:10 +03:00
|
|
|
grep -e ' ERROR ' -e ' WARN ' test_log_1.txt && 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"
|
|
|
|
set -x
|
2022-12-12 17:11:10 +03:00
|
|
|
|
|
|
|
ARG=(--config tests/config.yaml "$DATABASE_URL")
|
|
|
|
$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
|
|
|
|
|
|
|
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-12-12 17:11:10 +03:00
|
|
|
grep -e ' ERROR ' -e ' WARN ' test_log_2.txt && exit 1
|
2022-11-30 19:57:27 +03:00
|
|
|
|
|
|
|
>&2 echo "All integration tests have passed"
|