Files
magpie/internal/agent/dsh_models_stale_test.go
T
yetone 92c798aac5 agent: dsh's models are built again every 30 minutes at rest, not 5
With a real-account HOME, an idle magpie allocated ~53 MB per 4 minutes,
and ~42 MB of it was dsh's wiring round building magpie's models again
because dshModelsFor (5 minutes) had passed, with provider.StampNow
unchanged. The forced build is only for what the stamp can't see: another
app rewriting an account's file, and models retired by date. Now it runs
every 30 minutes, and once more when the local day changes, so a dated
retirement still reaches dsh's lists that day.

Run on mote:
- go test -count=1 ./internal/agent: ok (244s)
- GOOS=windows go vet, GOOS=linux go vet -tags nogui ./internal/agent: ok
- gofmt -l: clean
Broken by hand: dshModelsFor back at 5 minutes, TestDshModelsStale is red
(10 and 29 minutes counted stale). The existing "unseen" subtest still
rebuilds models dshModelsFor old.
Not tried: a measured idle allocation on a real binary; that comes with
the next release's acrss/ad run.
2026-11-11 08:02:10 +08:00

31 lines
874 B
Go

package agent
import (
"testing"
"time"
)
// An idle magpie builds dsh's models again at most every dshModelsFor,
// not every few minutes, and once more when the day changes, for the
// models retired by date.
func TestDshModelsStale(t *testing.T) {
at := time.Date(2026, 11, 11, 12, 0, 0, 0, time.Local)
for _, c := range []struct {
now time.Time
stale bool
}{
{at.Add(10 * time.Minute), false},
{at.Add(29 * time.Minute), false},
{at.Add(dshModelsFor), true},
{time.Date(2026, 11, 12, 0, 1, 0, 0, time.Local), true},
} {
if got := dshModelsStale(at, c.now); got != c.stale {
t.Errorf("built at %v, now %v: stale %v, want %v", at, c.now, got, c.stale)
}
}
late := time.Date(2026, 11, 11, 23, 58, 0, 0, time.Local)
if !dshModelsStale(late, late.Add(5*time.Minute)) {
t.Error("models built before midnight are kept into the next day")
}
}