summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-06-05 16:22:32 +0300
committerPaul Buetow <paul@buetow.org>2026-06-05 16:22:32 +0300
commit3d3c5fda1021206655783b101e85f0b41f3588f4 (patch)
tree61c1048d91c6ed6e8bd5e97c786db7411b4b921a /tests
parent41aac9fb4aed365b8f0fc8ec09798268da5f036c (diff)
Add timeouts for generation tools
Diffstat (limited to 'tests')
-rwxr-xr-xtests/cli.sh88
-rwxr-xr-xtests/helpers.sh29
2 files changed, 117 insertions, 0 deletions
diff --git a/tests/cli.sh b/tests/cli.sh
index e4a94a6..367cd1a 100755
--- a/tests/cli.sh
+++ b/tests/cli.sh
@@ -927,11 +927,13 @@ HEIGHT=1200
THUMBHEIGHT=300
MAXPREVIEWS=40
IMAGE_JOBS=3
+IMAGEMAGICK_TIMEOUT=60
RANDOM_SEED=''
SHUFFLE=no
SPLASH_PAGE=yes
TARBALL_INCLUDE=yes
TARBALL_SUFFIX=.tar
+TAR_TIMEOUT=120
TAR_OPTS=( -c )
ORIGINAL_BASEPATH=''
EOF
@@ -1062,11 +1064,13 @@ HEIGHT=120
THUMBHEIGHT=30
MAXPREVIEWS=7
IMAGE_JOBS=3
+IMAGEMAGICK_TIMEOUT=60
RANDOM_SEED=''
SHUFFLE=yes
SPLASH_PAGE=yes
TARBALL_INCLUDE=no
TARBALL_SUFFIX=.tar
+TAR_TIMEOUT=120
TAR_OPTS=( -c )
ORIGINAL_BASEPATH=''
EOF
@@ -1099,11 +1103,13 @@ HEIGHT=120
THUMBHEIGHT=30
MAXPREVIEWS=8
IMAGE_JOBS=3
+IMAGEMAGICK_TIMEOUT=60
RANDOM_SEED=''
SHUFFLE=no
SPLASH_PAGE=yes
TARBALL_INCLUDE=no
TARBALL_SUFFIX=.tar
+TAR_TIMEOUT=120
TAR_OPTS=( -c )
ORIGINAL_BASEPATH=''
EOF
@@ -1161,11 +1167,13 @@ HEIGHT=456
THUMBHEIGHT=45
MAXPREVIEWS=9
IMAGE_JOBS=2
+IMAGEMAGICK_TIMEOUT=60
RANDOM_SEED=cli-seed
SHUFFLE=yes
SPLASH_PAGE=no
TARBALL_INCLUDE=yes
TARBALL_SUFFIX=.tar
+TAR_TIMEOUT=120
TAR_OPTS=( -c )
ORIGINAL_BASEPATH=''
EOF
@@ -2205,6 +2213,80 @@ test_generate_imagemagick_failure_preserves_dist() {
test::teardown
}
+test_generate_imagemagick_timeout_preserves_dist() {
+ local config_file
+ local fake_bin
+ local output
+
+ test::setup
+ fake_bin="$TEST_TMPDIR/bin"
+ config_file="$TEST_TMPDIR/photoalbum.conf"
+
+ test::install_hanging_imagemagick "$fake_bin"
+ mkdir -p "$TEST_TMPDIR/incoming" "$TEST_TMPDIR/dist"
+ printf 'fake image\n' > "$TEST_TMPDIR/incoming/01.jpg"
+ printf 'old dist\n' > "$TEST_TMPDIR/dist/index.html"
+ printf 'keep me\n' > "$TEST_TMPDIR/dist/sentinel"
+ test::write_album_config \
+ "$config_file" "$TEST_TMPDIR/incoming" "$TEST_TMPDIR/dist" \
+ 'Hanging ImageMagick album' 40
+ printf 'IMAGEMAGICK_TIMEOUT=1\n' >> "$config_file"
+
+ output=$(
+ cd "$TEST_TMPDIR"
+ PATH="$fake_bin:$PATH" TEST_HANG_SECONDS=2 \
+ test::capture_failure_output "$TEST_PHOTOALBUM" --generate
+ )
+
+ test::assert_contains \
+ 'ERROR: ImageMagick timed out after 1 seconds' "$output"
+ test "$(<"$TEST_TMPDIR/dist/index.html")" = 'old dist'
+ test "$(<"$TEST_TMPDIR/dist/sentinel")" = 'keep me'
+ test::assert_path_absent "$TEST_TMPDIR/dist/photos/01.jpg"
+ test::assert_path_absent "$TEST_TMPDIR/dist/photoalbum.json"
+ test::assert_no_staging_dirs "$TEST_TMPDIR"
+ test::teardown
+}
+
+test_generate_tar_timeout_preserves_dist() {
+ local config_file
+ local fake_bin
+ local output
+
+ test::setup
+ fake_bin="$TEST_TMPDIR/bin"
+ config_file="$TEST_TMPDIR/photoalbum.conf"
+
+ test::install_fake_imagemagick "$fake_bin"
+ PATH="$fake_bin:$PATH" \
+ test::generate_fixture_images "$TEST_TMPDIR/incoming"
+ test::install_hanging_tar "$fake_bin"
+ mkdir -p "$TEST_TMPDIR/dist"
+ printf 'old dist\n' > "$TEST_TMPDIR/dist/index.html"
+ printf 'keep me\n' > "$TEST_TMPDIR/dist/sentinel"
+ test::write_album_config \
+ "$config_file" "$TEST_TMPDIR/incoming" "$TEST_TMPDIR/dist" \
+ 'Hanging tar album' 40
+ {
+ printf 'TARBALL_INCLUDE=yes\n'
+ printf 'TAR_TIMEOUT=1\n'
+ } >> "$config_file"
+
+ output=$(
+ cd "$TEST_TMPDIR"
+ PATH="$fake_bin:$PATH" TEST_HANG_SECONDS=2 \
+ test::capture_failure_output "$TEST_PHOTOALBUM" --generate
+ )
+
+ test::assert_contains 'ERROR: tar timed out after 1 seconds' "$output"
+ test "$(<"$TEST_TMPDIR/dist/index.html")" = 'old dist'
+ test "$(<"$TEST_TMPDIR/dist/sentinel")" = 'keep me'
+ test::assert_path_absent "$TEST_TMPDIR/dist/photoalbum.json"
+ test::assert_find_count 0 "$TEST_TMPDIR/dist" '*.tar'
+ test::assert_no_staging_dirs "$TEST_TMPDIR"
+ test::teardown
+}
+
test_generate_template_failure_preserves_dist() {
local config_file
local fake_bin
@@ -2867,6 +2949,12 @@ main() {
'--generate ImageMagick failure preserves final dist' \
test_generate_imagemagick_failure_preserves_dist
test::run_case \
+ '--generate ImageMagick timeout preserves final dist' \
+ test_generate_imagemagick_timeout_preserves_dist
+ test::run_case \
+ '--generate tar timeout preserves final dist' \
+ test_generate_tar_timeout_preserves_dist
+ test::run_case \
'--generate template failure preserves final dist' \
test_generate_template_failure_preserves_dist
test::run_case \
diff --git a/tests/helpers.sh b/tests/helpers.sh
index ca313fd..bf6000e 100755
--- a/tests/helpers.sh
+++ b/tests/helpers.sh
@@ -288,6 +288,21 @@ MAGICK
cp "$bin_dir/magick" "$bin_dir/convert"
}
+test::install_hanging_imagemagick() {
+ local -r bin_dir="$1"; shift
+
+ mkdir -p "$bin_dir"
+
+ cat > "$bin_dir/magick" <<'MAGICK'
+#!/usr/bin/env bash
+set -euo pipefail
+
+sleep "${TEST_HANG_SECONDS:-5}"
+MAGICK
+ chmod 0755 "$bin_dir/magick"
+ cp "$bin_dir/magick" "$bin_dir/convert"
+}
+
test::install_failing_generation_tools() {
local -r bin_dir="$1"; shift
local name
@@ -392,6 +407,20 @@ TAR
chmod 0755 "$bin_dir/tar"
}
+test::install_hanging_tar() {
+ local -r bin_dir="$1"; shift
+
+ mkdir -p "$bin_dir"
+
+ cat > "$bin_dir/tar" <<'TAR'
+#!/usr/bin/env bash
+set -euo pipefail
+
+sleep "${TEST_HANG_SECONDS:-5}"
+TAR
+ chmod 0755 "$bin_dir/tar"
+}
+
test::install_coreutils_without_imagemagick() {
local -r bin_dir="$1"; shift
local command_path