Skip to content

Commit 6239413

Browse files
committed
Test mapcache_seed parallel worker mode
1 parent 77b589b commit 6239413

File tree

1 file changed

+63
-6
lines changed

1 file changed

+63
-6
lines changed

tests/run_tests.sh

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# Project: MapCache
44
# Purpose: MapCache tests
5-
# Author: Even Rouault
5+
# Author: Even Rouault, Maris Nartiss
66
#
77
#*****************************************************************************
8-
# Copyright (c) 2017 Regents of the University of Minnesota.
8+
# Copyright (c) 2017, 2025 Regents of the University of Minnesota.
99
#
1010
# Permission is hereby granted, free of charge, to any person obtaining a
1111
# copy of this software and associated documentation files (the "Software"),
@@ -30,10 +30,10 @@ set -e
3030

3131
MAPCACHE_CONF=/tmp/mc/mapcache.xml
3232

33-
sudo rm -rf /tmp/mc/global
33+
rm -rf /tmp/mc/global
3434
mapcache_seed -c /tmp/mc/mapcache.xml -t global --force -z 0,1
35-
gdalinfo -checksum /tmp/mc/global/GoogleMapsCompatible/00/000/000/000/000/000/000.jpg | grep Checksum=20574 >/dev/null || (echo "Did not get expected checksum"; gdalinfo -checksum /tmp/mc/global/GoogleMapsCompatible/00/000/000/000/000/000/000.jpg; /bin/false)
36-
sudo rm -rf /tmp/mc/global
35+
gdalinfo /tmp/mc/global/GoogleMapsCompatible/00/000/000/000/000/000/000.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size"; gdalinfo /tmp/mc/global/GoogleMapsCompatible/00/000/000/000/000/000/000.jpg; /bin/false)
36+
rm -rf /tmp/mc/global
3737

3838
curl -s "http://localhost/mapcache/?SERVICE=WMS&REQUEST=GetCapabilities" | xmllint --format - > /tmp/wms_capabilities.xml
3939
diff -u /tmp/wms_capabilities.xml expected
@@ -42,8 +42,65 @@ curl -s "http://localhost/mapcache/wmts?SERVICE=WMTS&REQUEST=GetCapabilities" |
4242
diff -u /tmp/wmts_capabilities.xml expected
4343

4444
curl -s "http://localhost/mapcache/wmts/1.0.0/global/default/GoogleMapsCompatible/0/0/0.jpg" > /tmp/0.jpg
45-
gdalinfo -checksum /tmp/0.jpg | grep Checksum=20574 >/dev/null || (echo "Did not get expected checksum"; gdalinfo -checksum /tmp/0.jpg; /bin/false)
45+
gdalinfo /tmp/0.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size"; gdalinfo /tmp/0.jpg; /bin/false)
4646

4747
curl -s "http://localhost/mapcache/wmts/1.0.0/global/default/GoogleMapsCompatible/0/0/0.jpg" > /tmp/0_bis.jpg
4848
diff /tmp/0.jpg /tmp/0_bis.jpg
4949

50+
51+
# --- Test parallel seeding ---
52+
echo "== Testing parallel seeding with -p 4 =="
53+
rm -rf /tmp/mc/global
54+
mapcache_seed -c /tmp/mc/mapcache.xml -t global --force -z 0,2 -p 4
55+
gdalinfo /tmp/mc/global/GoogleMapsCompatible/00/000/000/000/000/000/000.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size for tile 0/0/0"; gdalinfo /tmp/mc/global/GoogleMapsCompatible/00/000/000/000/000/000/000.jpg; /bin/false)
56+
gdalinfo /tmp/mc/global/GoogleMapsCompatible/01/000/000/000/000/000/000.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size for tile 1/0/0"; gdalinfo /tmp/mc/global/GoogleMapsCompatible/01/000/000/000/000/000/000.jpg; /bin/false)
57+
gdalinfo /tmp/mc/global/GoogleMapsCompatible/02/000/000/000/000/000/000.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size for tile 2/0/0"; gdalinfo /tmp/mc/global/GoogleMapsCompatible/02/000/000/000/000/000/000.jpg; /bin/false)
58+
echo "OK: Parallel seeding with -p 4 successful"
59+
rm -rf /tmp/mc/global
60+
61+
# --- Test parallel seeding with -p 1 ---
62+
echo "== Testing parallel seeding with -p 1 =="
63+
rm -rf /tmp/mc/global
64+
mapcache_seed -c /tmp/mc/mapcache.xml -t global --force -z 0,2 -p 1
65+
gdalinfo /tmp/mc/global/GoogleMapsCompatible/00/000/000/000/000/000/000.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size for tile 0/0/0"; exit 1)
66+
gdalinfo /tmp/mc/global/GoogleMapsCompatible/01/000/000/000/000/000/000.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size for tile 1/0/0"; exit 1)
67+
gdalinfo /tmp/mc/global/GoogleMapsCompatible/02/000/000/000/000/000/000.jpg | grep "Size is 256, 256" >/dev/null || (echo "Invalid image size for tile 2/0/0"; exit 1)
68+
echo "OK: Parallel seeding with -p 1 successful"
69+
rm -rf /tmp/mc/global
70+
71+
# --- Test graceful shutdown ---
72+
echo "== Testing graceful shutdown of parallel seeder =="
73+
rm -rf /tmp/mc_shutdown
74+
mkdir -p /tmp/mc_shutdown
75+
cp /tmp/mc/mapcache.xml /tmp/mc/mapcache_shutdown.xml
76+
sed -i 's|<base>/tmp/mc</base>|<base>/tmp/mc_shutdown</base>|' /tmp/mc/mapcache_shutdown.xml
77+
# Run seeder in the background, in its own process group
78+
set -m
79+
mapcache_seed -c /tmp/mc/mapcache_shutdown.xml -t global -z 0,8 -p 4 -q &
80+
PID=$!
81+
set +m
82+
# Give it a moment to start seeding
83+
sleep 2
84+
PGID=$(ps -o pgid= $PID | xargs)
85+
if [ -z "$PGID" ]; then
86+
echo "Could not get PGID of seeder process. Test cannot continue."
87+
exit 1
88+
fi
89+
# Send SIGINT to the process group
90+
echo "Sending SIGINT to process group $PGID"
91+
kill -INT -$PGID
92+
# Wait for the process to terminate, with a timeout
93+
if wait $PID 2>/dev/null; then
94+
echo "OK: Seeder terminated gracefully on SIGINT"
95+
else
96+
# The process might have already exited and `wait` fails.
97+
# Let's check if it's still running.
98+
if ps -p $PID > /dev/null; then
99+
echo "Error: Seeder did not terminate gracefully"
100+
kill -9 -$PGID
101+
exit 1
102+
else
103+
echo "OK: Seeder terminated gracefully on SIGINT"
104+
fi
105+
fi
106+
rm -rf /tmp/mc_shutdown

0 commit comments

Comments
 (0)