#!/usr/bin/env bash # Test: warmup_schedule triggers warmup at the configured cron time. # # Strategy: set warmup_schedule to "* * * * *" (every minute) so the # supervisor fires at the next 60-second boundary. We also set a short # dir-cache-time so the mount comes up fast. After the mount is ready we # wait up to 70 s for a "Scheduled warmup triggered" log line. # # Requires: root (for FUSE mounts), a real mock NAS for rclone to connect to. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/../harness/helpers.sh" source "$SCRIPT_DIR/../harness/mock-nas.sh" require_root setup_test_env trap teardown_test_env EXIT # Seed a file in the mock NAS so warmup has something to do start_mock_nas mkdir -p "$NAS_ROOT/warmup-dir" echo "test content" > "$NAS_ROOT/warmup-dir/file.txt" # Generate config with: # - a warmup rule pointing at the seeded directory # - warmup_schedule = "* * * * *" (every minute — fires within 60 s) # - warmup.auto = false (we rely on the cron schedule only) gen_config \ "warmup_auto=false" \ "warmup_schedule=* * * * *" \ "warmup.rules=[[warmup.rules]]\nshare = \"data\"\npath = \"warmup-dir\"" # Start warpgate and wait for the mount to be ready start_warpgate wait_for_mount 60 wait_for_rc_api 30 # The cron expression "* * * * *" fires every minute. # We allow up to 90 s for the trigger log line to appear. TIMEOUT=90 DEADLINE=$((SECONDS + TIMEOUT)) triggered=0 while [[ $SECONDS -lt $DEADLINE ]]; do if grep -q "Scheduled warmup triggered" "$TEST_DIR/warpgate.log" 2>/dev/null; then triggered=1 break fi sleep 2 done if [[ $triggered -eq 0 ]]; then echo "FAIL: 'Scheduled warmup triggered' not found in log within ${TIMEOUT}s" echo "--- warpgate.log tail ---" tail -30 "$TEST_DIR/warpgate.log" 2>/dev/null || true exit 1 fi # Verify the schedule string appears in the trigger log line if ! grep "Scheduled warmup triggered" "$TEST_DIR/warpgate.log" | grep -q "schedule"; then echo "FAIL: trigger log line should mention the schedule expression" exit 1 fi echo "PASS: $(basename "$0" .sh)"