Files
felhom-controller/controller/cmd/controller/oomlog_test.go
T
admin 5b3b541602
gates / gates (push) Successful in 31s
clear_hold (D64 = B) + the box command through the running controller (R-1343), R-1340, R-1341 — tests red first; commit only
- clear_hold: a fifth verb in the closed operator-action list; lifts a hold of any reason in the RUNNING
  controller (memory + settings.json together), forgets the update's held flag, drops a waiting put-back
  from the app-stop marker (copy kept). Refused on a bad name or no hold. No new event type.
- --clear-restore-hold asks the running controller over <data dir>/ctl/hold.sock (unix, 0600, peer uid
  checked, no TCP); edits settings.json only when no controller answers, and says so (in-guest restart).
- R-1340: the operator's HELD STOPPED mail is built from the hold record (restore kind, mixed cause,
  failed put-back step, database replay or not, kept copy) — never the option-C database story by default.
- R-1341: the OOM WARN line once per new kill (container, start time, kill count); event unchanged.
2026-10-29 12:49:46 +01:00

65 lines
2.4 KiB
Go

package main
import (
"testing"
"gitea.dooplex.hu/admin/felhom-controller/internal/stacks"
)
// R-1341: the „[WARN] [deadapp] … was OOM-killed" line goes out once per NEW kill, not every 30-s scan.
//
// RED-PROOF (2026-10-29): with oomLogGate.fresh returning its input unchanged (the pre-R-1341 loop logged every
// container every scan), TestR1341_ASecondScanOfTheSameKillLogsNothing fails on „logged 1 line(s), want 0".
func oom(container, started string, kills int64) stacks.OOMContainer {
return stacks.OOMContainer{Stack: "gokapi", Container: container, StartedAt: started, Kills: kills}
}
func TestR1341_ASecondScanOfTheSameKillLogsNothing(t *testing.T) {
g := &oomLogGate{}
scan := []stacks.OOMContainer{oom("gokapi", "2026-10-29T09:02:00Z", 1)}
if got := g.fresh(scan); len(got) != 1 {
t.Fatalf("the first sighting must log, logged %d line(s)", len(got))
}
for i := 0; i < 5; i++ {
if got := g.fresh(scan); len(got) != 0 {
t.Fatalf("scan %d of the same kill logged %d line(s), want 0", i+2, len(got))
}
}
}
func TestR1341_ANewKillLogsAgain(t *testing.T) {
g := &oomLogGate{}
g.fresh([]stacks.OOMContainer{oom("gokapi", "2026-10-29T09:02:00Z", 1)})
got := g.fresh([]stacks.OOMContainer{oom("gokapi", "2026-10-29T09:02:00Z", 2)})
if len(got) != 1 || got[0].Kills != 2 {
t.Fatalf("a new kill (count 1→2) must log once, got %+v", got)
}
if got := g.fresh([]stacks.OOMContainer{oom("gokapi", "2026-10-29T09:02:00Z", 2)}); len(got) != 0 {
t.Fatalf("the same new kill must not log twice, got %+v", got)
}
}
func TestR1341_ARestartedContainerLogsAgain(t *testing.T) {
g := &oomLogGate{}
g.fresh([]stacks.OOMContainer{oom("gokapi", "2026-10-29T09:02:00Z", 1)})
if got := g.fresh([]stacks.OOMContainer{oom("gokapi", "2026-10-29T09:30:00Z", 1)}); len(got) != 1 {
t.Fatalf("a restarted container's kill must log, got %+v", got)
}
}
// Two containers are judged apart; one that leaves the scan is forgotten, so its return logs again.
func TestR1341_ContainersAreJudgedApart(t *testing.T) {
g := &oomLogGate{}
a, b := oom("a", "t1", 1), oom("b", "t1", 1)
if got := g.fresh([]stacks.OOMContainer{a, b}); len(got) != 2 {
t.Fatalf("first scan: %+v", got)
}
if got := g.fresh([]stacks.OOMContainer{a}); len(got) != 0 {
t.Fatalf("a seen again must not log: %+v", got)
}
if got := g.fresh([]stacks.OOMContainer{a, b}); len(got) != 1 || got[0].Container != "b" {
t.Fatalf("b came back after leaving the scan: %+v", got)
}
}