Skip to content

Commit

Permalink
cleanup test.sh, fix json rounding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Oct 20, 2024
1 parent dc06313 commit fd86132
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 60 deletions.
4 changes: 2 additions & 2 deletions tests/expected/auto/mb_jpg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"http://localhost:3111/geography-class-jpg/{z}/{x}/{y}"
],
"bounds": [
-180.0,
-180,
-85.0511,
180.0,
180,
85.0511
],
"description": "One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. ",
Expand Down
8 changes: 4 additions & 4 deletions tests/expected/auto/mb_png.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"http://localhost:3111/geography-class-png/{z}/{x}/{y}"
],
"bounds": [
-180.0,
-180,
-85.0511,
180.0,
180,
85.0511
],
"center": [
0.0,
20.0,
0,
20,
0
],
"description": "One of the example maps that comes with TileMill - a bright & colorful world map that blends retro and high-tech with its folded paper texture and interactive flag tooltips. ",
Expand Down
12 changes: 6 additions & 6 deletions tests/expected/auto/pmt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"http://localhost:3111/stamen_toner__raster_CC-BY-ODbL_z3/{z}/{x}/{y}"
],
"bounds": [
-180.0,
-85.0,
180.0,
85.0
-180,
-85,
180,
85
],
"center": [
0.0,
0.0,
0,
0,
0
],
"maxzoom": 3,
Expand Down
6 changes: 3 additions & 3 deletions tests/expected/auto/table_source.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
}
],
"bounds": [
-2.0,
-1.0,
-2,
-1,
142.84131509869133,
45.0
45
],
"name": "table_source",
"foo": {
Expand Down
78 changes: 33 additions & 45 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ function wait_for {
PROC_NAME=$2
TEST_URL=$3
echo "Waiting for $PROC_NAME ($PROCESS_ID) to start by checking $TEST_URL to be valid..."
for i in {1..60}; do
for _ in {1..60}; do
if $CURL "$TEST_URL" 2>/dev/null >/dev/null; then
echo "$PROC_NAME is up!"
if [[ "$PROC_NAME" == "Martin" ]]; then
$CURL "$TEST_URL"
fi
return
fi
if ps -p $PROCESS_ID > /dev/null ; then
if ps -p "$PROCESS_ID" > /dev/null ; then
echo "$PROC_NAME is not up yet, waiting for $TEST_URL ..."
sleep 1
else
Expand All @@ -62,32 +62,31 @@ function kill_process {
PROCESS_ID=$1
PROC_NAME=$2
echo "Waiting for $PROC_NAME ($PROCESS_ID) to stop..."
kill $PROCESS_ID
for i in {1..50}; do
if ps -p $PROCESS_ID > /dev/null ; then
kill "$PROCESS_ID"
for _ in {1..50}; do
if ps -p "$PROCESS_ID" > /dev/null ; then
sleep 0.1
else
echo "$PROC_NAME ($PROCESS_ID) has stopped"
return
fi
done
echo "$PROC_NAME did not stop in time, killing it"
kill -9 $PROCESS_ID
kill -9 "$PROCESS_ID"
# wait for it to die using timeout and wait
timeout -k 1s 1s wait $PROCESS_ID || true;
timeout -k 1s 1s wait "$PROCESS_ID" || true;
}

test_jsn()
{
test_jsn() {
FILENAME="$TEST_OUT_DIR/$1.json"
URL="$MARTIN_URL/$2"

echo "Testing $(basename "$FILENAME") from $URL"
$CURL "$URL" | jq -e > "$FILENAME"
# jq before 1.6 had a different float->int behavior, so trying to make it consistent in all
$CURL "$URL" | jq -e 'walk(if type == "number" then .+0.0 else . end)' > "$FILENAME"
}

test_pbf()
{
test_pbf() {
FILENAME="$TEST_OUT_DIR/$1.pbf"
URL="$MARTIN_URL/$2"

Expand All @@ -100,8 +99,7 @@ test_pbf()
fi
}

test_png()
{
test_png() {
# 3rd argument is optional, .png by default
FILENAME="$TEST_OUT_DIR/$1.${3:-png}"
URL="$MARTIN_URL/$2"
Expand All @@ -114,15 +112,12 @@ test_png()
fi
}

test_jpg()
{
test_jpg() {
# test_png can test any image format, but this is a separate function to make it easier to find all the jpeg tests
test_png $1 $2 jpg
test_png "$1" "$2" jpg
}


test_font()
{
test_font() {
FILENAME="$TEST_OUT_DIR/$1.pbf"
URL="$MARTIN_URL/$2"

Expand All @@ -131,26 +126,23 @@ test_font()
}

# Delete a line from a file $1 that matches parameter $2
remove_line()
{
remove_line() {
FILE="$1"
LINE_TO_REMOVE="$2"
>&2 echo "Removing line '$LINE_TO_REMOVE' from $FILE"
grep -v "$LINE_TO_REMOVE" "${FILE}" > "${FILE}.tmp"
mv "${FILE}.tmp" "${FILE}"
}

test_log_has_str()
{
test_log_has_str() {
LOG_FILE="$1"
EXPECTED_TEXT="$2"
echo "Checking $LOG_FILE for expected text: '$EXPECTED_TEXT'"
grep -q "$EXPECTED_TEXT" "$LOG_FILE"
remove_line "$LOG_FILE" "$EXPECTED_TEXT"
}

test_martin_cp()
{
test_martin_cp() {
TEST_NAME="$1"
ARG=("${@:2}")

Expand All @@ -171,11 +163,9 @@ test_martin_cp()
# These tend to vary between runs. In theory, vacuuming might make it the same.
remove_line "$SUMMARY_FILE" "File size: "
remove_line "$SUMMARY_FILE" "Page count: "

}

validate_log()
{
validate_log() {
LOG_FILE="$1"
>&2 echo "Validating log file $LOG_FILE"

Expand All @@ -190,7 +180,10 @@ validate_log()
fi
}

echo "------------------------------------------------------------------------------------------------------------------------"
curl --version
jq --version
grep --version

# Make sure all targets are built - this way it won't timeout while waiting for it to start
# If set to "-", skip this step (e.g. when testing a pre-built binary)
Expand All @@ -199,7 +192,6 @@ if [[ "$MARTIN_BUILD_ALL" != "-" ]]; then
$MARTIN_BUILD_ALL
fi


echo "------------------------------------------------------------------------------------------------------------------------"
echo "Check HTTP server is running"
$CURL --head "$STATICS_URL/webp2.pmtiles"
Expand All @@ -217,10 +209,10 @@ export DATABASE_URL="$MARTIN_DATABASE_URL"

set -x
$MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" &
MARTIN_PROC_ID=`jobs -p | tail -n 1`
MARTIN_PROC_ID=$(jobs -p | tail -n 1)
{ set +x; } 2> /dev/null
trap "echo 'Stopping Martin server $MARTIN_PROC_ID...'; kill -9 $MARTIN_PROC_ID 2> /dev/null || true; echo 'Stopped Martin server $MARTIN_PROC_ID';" EXIT HUP INT TERM
wait_for $MARTIN_PROC_ID Martin "$MARTIN_URL/health"
wait_for "$MARTIN_PROC_ID" Martin "$MARTIN_URL/health"
unset DATABASE_URL

>&2 echo "Test catalog"
Expand Down Expand Up @@ -295,7 +287,7 @@ test_pbf points_empty_srid_0_0_0 points_empty_srid/0/0/0
test_jsn tbl_comment MixPoints
test_jsn fnc_comment function_Mixed_Name

kill_process $MARTIN_PROC_ID Martin
kill_process "$MARTIN_PROC_ID" Martin

test_log_has_str "$LOG_FILE" 'WARN martin::pg::query_tables] Table public.table_source has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin::fonts] Ignoring duplicate font Overpass Mono Regular from tests'
Expand All @@ -314,16 +306,16 @@ mkdir -p "$TEST_OUT_DIR"
ARG=(--save-config "${TEST_OUT_DIR}/save_config.yaml" tests/fixtures/pmtiles2)
set -x
$MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" &
MARTIN_PROC_ID=`jobs -p | tail -n 1`
MARTIN_PROC_ID=$(jobs -p | tail -n 1)

{ set +x; } 2> /dev/null
trap "echo 'Stopping Martin server $MARTIN_PROC_ID...'; kill -9 $MARTIN_PROC_ID 2> /dev/null || true; echo 'Stopped Martin server $MARTIN_PROC_ID';" EXIT HUP INT TERM
wait_for $MARTIN_PROC_ID Martin "$MARTIN_URL/health"
wait_for "$MARTIN_PROC_ID" Martin "$MARTIN_URL/health"

>&2 echo "Test catalog"
test_jsn catalog_auto catalog

kill_process $MARTIN_PROC_ID Martin
kill_process "$MARTIN_PROC_ID" Martin
validate_log "$LOG_FILE"


Expand All @@ -339,10 +331,10 @@ ARG=(--config tests/config.yaml --max-feature-count 1000 --save-config "${TEST_O
export DATABASE_URL="$MARTIN_DATABASE_URL"
set -x
$MARTIN_BIN "${ARG[@]}" 2>&1 | tee "$LOG_FILE" &
MARTIN_PROC_ID=`jobs -p | tail -n 1`
MARTIN_PROC_ID=$(jobs -p | tail -n 1)
{ set +x; } 2> /dev/null
trap "echo 'Stopping Martin server $MARTIN_PROC_ID...'; kill -9 $MARTIN_PROC_ID 2> /dev/null || true; echo 'Stopped Martin server $MARTIN_PROC_ID';" EXIT HUP INT TERM
wait_for $MARTIN_PROC_ID Martin "$MARTIN_URL/health"
wait_for "$MARTIN_PROC_ID" Martin "$MARTIN_URL/health"
unset DATABASE_URL

>&2 echo "Test catalog"
Expand Down Expand Up @@ -379,7 +371,7 @@ test_font font_3 font/Overpass%20Mono%20Regular,Overpass%20Mono%20Light/0-2
test_jsn tbl_comment_cfg MixPoints
test_jsn fnc_comment_cfg fnc_Mixed_Name

kill_process $MARTIN_PROC_ID Martin
kill_process "$MARTIN_PROC_ID" Martin
test_log_has_str "$LOG_FILE" 'WARN martin::pg::query_tables] Table public.table_source has no spatial index on column geom'
test_log_has_str "$LOG_FILE" 'WARN martin::fonts] Ignoring duplicate font Overpass Mono Regular from tests'
validate_log "$LOG_FILE"
Expand Down Expand Up @@ -435,18 +427,14 @@ if [[ "$MBTILES_BIN" != "-" ]]; then
$MBTILES_BIN meta-get ./tests/fixtures/mbtiles/world_cities.mbtiles missing_value 2>&1 | tee "$TEST_OUT_DIR/meta-get_missing_value.txt"
$MBTILES_BIN validate ./tests/fixtures/mbtiles/zoomed_world_cities.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-ok.txt"

set +e
$MBTILES_BIN validate ./tests/fixtures/files/invalid-tile-idx.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-tiles.txt"
if [[ $? -eq 0 ]]; then
if $MBTILES_BIN validate ./tests/fixtures/files/invalid-tile-idx.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-tiles.txt"; then
echo "ERROR: validate with invalid-tile-idx.mbtiles should have failed"
exit 1
fi
$MBTILES_BIN validate ./tests/fixtures/files/bad_hash.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-hash.txt"
if [[ $? -eq 0 ]]; then
if $MBTILES_BIN validate ./tests/fixtures/files/bad_hash.mbtiles 2>&1 | tee "$TEST_OUT_DIR/validate-bad-hash.txt"; then
echo "ERROR: validate with bad_hash.mbtiles should have failed"
exit 1
fi
set -e

cp ./tests/fixtures/files/bad_hash.mbtiles "$TEST_TEMP_DIR/fix_bad_hash.mbtiles"
$MBTILES_BIN validate --agg-hash update "$TEST_TEMP_DIR/fix_bad_hash.mbtiles" 2>&1 | tee "$TEST_OUT_DIR/validate-fix.txt"
Expand Down

0 comments on commit fd86132

Please sign in to comment.