diff --git a/tests/os/appliance-miner-recovery-leg.sh b/tests/os/appliance-miner-recovery-leg.sh index eeec1e927d..c375f62ec9 100644 --- a/tests/os/appliance-miner-recovery-leg.sh +++ b/tests/os/appliance-miner-recovery-leg.sh @@ -92,11 +92,38 @@ miner_watch_restore() { return "$failed" } miner_fastpath_receipt() { - [ -e /usr/local/sbin/pithead-miner-recovery ] || return 0 - grep -Fq 'proxy was recreated' /usr/local/sbin/pithead-miner-recovery || return 0 - timeout 10 journalctl --no-pager --since "@$(cat "$T3375/backup-at")" \ - -u pithead-miner-recovery.service | grep -Fq 'proxy was recreated' || return 1 - printf '%s\n' 'pithead-t3375: fastpath_restart=observed' + local recovery_bin cursor='' matches='' window='' found=0 + recovery_bin=${MINER_RECOVERY_BIN:-/usr/local/sbin/pithead-miner-recovery} + [ -e "$recovery_bin" ] || return 0 + grep -Fq 'proxy was recreated' "$recovery_bin" || return 0 + if [ -s "$T3375/fastpath-cursor" ]; then + window=journal-cursor + cursor=$(cat "$T3375/fastpath-cursor") + if timeout 10 journalctl --no-pager --after-cursor="$cursor" -u pithead-miner-recovery.service | + grep -Fq 'proxy was recreated'; then + found=1 + fi + else + window=backup-at-marker + if timeout 10 journalctl --no-pager --since "@$(cat "$T3375/backup-at")" -u pithead-miner-recovery.service | + grep -Fq 'proxy was recreated'; then + found=1 + fi + fi + if [ "$found" = 1 ]; then + printf '%s\n' 'pithead-t3375: fastpath_restart=observed' + return 0 + fi + printf 'pithead-t3375: fastpath_restart=missing window=%s backup_at=%s\n' \ + "$window" "$(cat "$T3375/backup-at" 2>/dev/null || printf 'unknown')" + matches=$(timeout 10 journalctl --no-pager --since '-30 minutes' -u pithead-miner-recovery.service | + grep -E 'restarting xmrig' | tail -n 5) || matches='' + if [ -n "$matches" ]; then + printf 'pithead-t3375: recovery unit restart lines in the last 30 minutes:\n%s\n' "$matches" + else + printf '%s\n' 'pithead-t3375: no recovery restart line in the last 30 minutes' + fi + return 1 } miner_watch() { local end=$((SECONDS + 1200)) @@ -340,6 +367,7 @@ miner_guest_dispatch() { identity) podman inspect --format '{{.Id}} {{.State.StartedAt}}' xmrig-proxy ;; backup-ready) podman inspect --format '{{.Id}}' xmrig-proxy >"$T3375/proxy-id" + timeout 10 journalctl --no-pager -n 0 --show-cursor | sed -n 's/^-- cursor: //p' >"$T3375/fastpath-cursor" || true ;; backup-applied) touch "$T3375/backup-applied" diff --git a/tests/os/selftest-miner-recovery.sh b/tests/os/selftest-miner-recovery.sh index bdff2a3af4..b3a52becc8 100644 --- a/tests/os/selftest-miner-recovery.sh +++ b/tests/os/selftest-miner-recovery.sh @@ -317,3 +317,48 @@ if miner_watch_restore; then fi [ -e "$T3375/paused" ] printf '%s\n' 'PASS: failed watchdog restoration retains its control files' +MINER_RECOVERY_BIN="$work/recovery" +printf '%s\n' 'pithead-miner-recovery: local miner proxy was recreated while the miner was disconnected; restarting xmrig' >"$MINER_RECOVERY_BIN" +printf '%s\n' 1700000000 >"$T3375/backup-at" +export PROXY_STARTED_AT=4444 +journalctl() { + case "$*" in + *--show-cursor*) printf -- '-- cursor: s=0000000000000000;i=2;b=0;m=0;r=0;u=11111111111111111111111111111111\n' ;; + *--after-cursor*) printf '%s\n' 'Nov 26 10:00:00 guest pithead-miner-recovery[9]: pithead-miner-recovery: proxy was recreated' ;; + *) : ;; + esac +} +miner_guest_dispatch backup-ready +[ "$(cat "$T3375/fastpath-cursor")" = 's=0000000000000000;i=2;b=0;m=0;r=0;u=11111111111111111111111111111111' ] +miner_fastpath_receipt >"$work/receipt" +grep -Fxq 'pithead-t3375: fastpath_restart=observed' "$work/receipt" +journalctl() { :; } +if miner_fastpath_receipt >"$work/receipt"; then + echo 'FAIL: a trial with no recovery restart line passed the receipt' + exit 1 +fi +grep -Fq 'fastpath_restart=missing window=journal-cursor' "$work/receipt" +grep -Fq 'no recovery restart line in the last 30 minutes' "$work/receipt" +printf '%s\n' 'PASS: a restart recorded only before the trial cursor window is never credited to it' +journalctl() { + case "$*" in + *'--since @'*) printf '%s\n' 'Nov 26 10:00:00 guest pithead-miner-recovery[9]: pithead-miner-recovery: proxy was recreated' ;; + *) : ;; + esac +} +rm -f "$T3375/fastpath-cursor" +miner_fastpath_receipt >"$work/receipt" +grep -Fxq 'pithead-t3375: fastpath_restart=observed' "$work/receipt" +journalctl() { + case "$*" in + *'--since -30 minutes'*) printf '%s\n' 'Nov 26 10:00:00 guest pithead-miner-recovery[9]: pithead-miner-recovery: active local miner disconnected for 300 seconds; restarting xmrig' ;; + *) : ;; + esac +} +if miner_fastpath_receipt >"$work/receipt"; then + echo 'FAIL: an absent restart inside the marker window passed the receipt' + exit 1 +fi +grep -Fq 'fastpath_restart=missing window=backup-at-marker' "$work/receipt" +grep -Fq 'disconnected for 300 seconds; restarting xmrig' "$work/receipt" +printf '%s\n' 'PASS: the fastpath receipt keeps the marker fallback and records why a missing restart was judged'