package webui import ( "path/filepath" "testing" "time" "bee/audit/internal/app" ) func TestNextHealthPollIntervalBacksOffAndResetsOnChange(t *testing.T) { interval := healthPollIntervalMin for i := 0; i < 10; i++ { interval = nextHealthPollInterval(interval, false) if interval > healthPollIntervalMax { t.Fatalf("interval=%s exceeded cap %s after %d steady ticks", interval, healthPollIntervalMax, i+1) } } if interval != healthPollIntervalMax { t.Fatalf("interval=%s want cap %s after repeated steady ticks", interval, healthPollIntervalMax) } // A change resets straight back to the fast floor, regardless of how // far the backoff had climbed. if got := nextHealthPollInterval(interval, true); got != healthPollIntervalMin { t.Fatalf("interval after change=%s want floor %s", got, healthPollIntervalMin) } } func TestHealthPollerPollPSUUnavailableReturnsFalseWithoutPanic(t *testing.T) { // ipmitool is not present in this test environment, so pollPSU must // degrade to a no-op (false, no crash) rather than erroring out the // poller loop. db, err := app.OpenComponentStatusDB(filepath.Join(t.TempDir(), "component-status.json")) if err != nil { t.Fatal(err) } p := newHealthPoller(db) if p.interval != healthPollIntervalMin { t.Fatalf("initial interval=%s want floor %s", p.interval, healthPollIntervalMin) } if got := p.pollPSU(); got { t.Fatalf("pollPSU()=%v want false when ipmitool is unavailable", got) } } func TestHealthPollIntervalBoundsAreSane(t *testing.T) { if healthPollIntervalMin >= healthPollIntervalMax { t.Fatalf("min %s must be less than max %s", healthPollIntervalMin, healthPollIntervalMax) } if healthPollIntervalMin != 60*time.Second { t.Fatalf("min=%s want 60s (unchanged default poll rate)", healthPollIntervalMin) } }