Files
felhom-controller/controller/internal/backup/main_test.go
T
admin 8ce496f124 R-488: backup tests read ONE health-wait clock; package 444 s -> ~2 s
waitForHealthy's 3 s settle / 5 s poll / 90 s timeout become package vars (production values
unchanged, pinned by TestR488_HealthWaitDefaultsAreProduction); TestMain shortens them once.
Measured before: 51 of 599 tests held 442 of 444 s, two not-running fixtures 279 s alone.
newOffboxManager now installs a failing SSH fake: TestOffbox_ConfirmedReset was spawning a
real 'ssh felhom@nas.local' and waiting out its 10 s ConnectTimeout.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-10-05 22:24:23 +02:00

51 lines
2.1 KiB
Go

package backup
import (
"os"
"testing"
"time"
)
// R-488 — the package's ONE test clock for the post-restore health wait.
//
// Before this, every restore fixture slept waitForHealthy's 3 s settle for real, and every fixture
// whose fake provider never reports "running" waited out the full 90 s timeout: measured 2026-10-05,
// 51 of 599 tests took ≥ 1 s and together held 442 of the package's 444 s, two of them alone 279 s.
// The production values are captured here BEFORE they are shortened, so the pin below reads what a
// box runs, not what the tests run.
var prodHealthSettle, prodHealthInterval, prodHealthTimeout = healthSettle, healthInterval, healthTimeout
func TestMain(m *testing.M) {
healthSettle = 0
healthInterval = 2 * time.Millisecond
healthTimeout = 50 * time.Millisecond
os.Exit(m.Run())
}
// The shortening is a TEST seam only: a box must still give a restored stack 3 s to settle, poll
// every 5 s, and wait 90 s before calling the restore unhealthy.
func TestR488_HealthWaitDefaultsAreProduction(t *testing.T) {
if prodHealthSettle != 3*time.Second || prodHealthInterval != 5*time.Second || prodHealthTimeout != 90*time.Second {
t.Fatalf("production health wait changed: settle=%v interval=%v timeout=%v (want 3s/5s/1m30s) — "+
"a restored app now gets a different grace on every box", prodHealthSettle, prodHealthInterval, prodHealthTimeout)
}
}
// The consequence the seam must not break: a stack that never comes up is still reported as a
// failure (only sooner), and one that is up is accepted.
func TestR488_WaitForHealthyStillJudges(t *testing.T) {
m := &Manager{}
m.stackProvider = &fakeRecoveryProvider{running: false}
start := time.Now()
if err := m.waitForHealthy("app", healthTimeout); err == nil {
t.Fatal("a stack that never reaches running must fail the health wait")
}
if d := time.Since(start); d > 5*time.Second {
t.Fatalf("the shortened clock is not in force: the wait took %v", d)
}
m.stackProvider = &fakeRecoveryProvider{running: true}
if err := m.waitForHealthy("app", healthTimeout); err != nil {
t.Fatalf("a running stack must pass: %v", err)
}
}