Files
felhom.eu/hub/internal/monitor/signed_job_waits_test.go
T
admin 1886030782
gates / gates (push) Successful in 2m9s
hub (unreleased): four silent failures tell the operator (R-1383, D78)
A hub daily check skipped while the hub was down; an operator mail that was never sent; a signed job a box did not
take; a signed job a box refused, and the guest-power watchdog's give-up (both from the agent). Operator-only.
No new table. Not deployed.

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-11-14 17:29:53 +01:00

56 lines
2.0 KiB
Go

package monitor
import (
"io"
"log"
"strings"
"testing"
"time"
)
// R-1383 (D78): a signed job the box never took is told ONCE, after two hours in the queue, to the box's customer
// record (the dispatcher keeps it operator-only). A fresh job, and a job that left the queue, raise nothing.
// COMPANION RED-PROOFS (observed, audits/night-build-2026-11-14/B/redproof-hub-signed-job.txt).
func TestSignedJobWait_OldJobToldOnceFreshJobNot(t *testing.T) {
now := time.Date(2026, 11, 14, 12, 0, 0, 0, time.UTC)
queue := []PendingSignedJob{
{HostID: "h1", JobID: "old", CreatedAt: now.Add(-3 * time.Hour)},
{HostID: "h1", JobID: "fresh", CreatedAt: now.Add(-119 * time.Minute)},
{HostID: "h2", JobID: "nodate"},
}
state := map[string]time.Time{}
var events []string
c := NewSignedJobWaitChecker(
func() ([]PendingSignedJob, error) { return queue, nil },
func(h string) string { return "cust-of-" + h },
func(k string) time.Time { return state[k] },
func(k string, t time.Time) error { state[k] = t; return nil },
func(cust, typ, sev, msg, details, src string) {
events = append(events, cust+"|"+typ+"|"+sev+"|"+msg+"|"+details)
}, log.New(io.Discard, "", 0))
c.now = func() time.Time { return now }
c.Check()
c.Check()
if len(events) != 1 {
t.Fatalf("events=%d, want ONE (the old job, once): %v", len(events), events)
}
for _, want := range []string{"cust-of-h1|signed_job_not_taken|warning|", "job old ", "h1", "3h0m0s", `"job_id":"old"`, `"waited_minutes":180`} {
if !strings.Contains(events[0], want) {
t.Errorf("the event lacks %q: %s", want, events[0])
}
}
// two minutes later the second job crosses the line: it is told, the first is not told again
now = now.Add(2 * time.Minute)
c.Check()
if len(events) != 2 || !strings.Contains(events[1], `"job_id":"fresh"`) {
t.Fatalf("after the second job crossed two hours: %v", events)
}
// the box takes both: nothing more, ever
queue = nil
now = now.Add(24 * time.Hour)
c.Check()
if len(events) != 2 {
t.Fatalf("an empty queue raised an event: %v", events[2:])
}
}