package hostops import ( "testing" "time" ) func TestAdmissionRegistrationCannotRevive(t *testing.T) { now := time.Date(2026, 10, 7, 0, 0, 0, 0, time.UTC) owner := RegistrationOwner{Console: "console", Enrollment: "enrollment", Controller: "request"} a := AppAdmission{V: 1, AppID: "app", Revision: 1, Epoch: 1, State: "open", Registrations: map[string]Registration{}, Effects: map[string]Effect{}} r := Registration{Kind: "create", Host: "x.example", Owner: owner, AppID: "app", Epoch: 1, Claim: SavedClaim{Absent: true}} if err := registerStart(&a, "operation", r, now); err != nil { t.Fatal(err) } if got := a.Registrations["operation"].Expires; !got.Equal(now.Add(90 * time.Second)) { t.Fatal(got) } a.State = "closed" if err := renewStart(&a, "operation", owner, now.Add(20*time.Second)); err != nil { t.Fatal(err) } if err := renewStart(&a, "operation", owner, now.Add(110*time.Second)); err == nil { t.Fatal("revived expired registration") } delete(a.Registrations, "operation") if err := renewStart(&a, "operation", owner, now.Add(40*time.Second)); err == nil { t.Fatal("recreated missing registration") } } func TestAdmissionEffectsDoNotExpireWithRegistration(t *testing.T) { a := AppAdmission{V: 1, AppID: "app", Revision: 1, Epoch: 1, State: "open", Registrations: map[string]Registration{}, Effects: map[string]Effect{}} e := Effect{ID: "one", OperationID: "op", AppID: "app", Resource: "store:environment", Action: "grant", State: "prepared", Owner: RegistrationOwner{Console: "console", Enrollment: "enrollment", Controller: "request"}} if err := prepareEffect(&a, e); err != nil { t.Fatal(err) } e.ID = "two" if err := prepareEffect(&a, e); err == nil { t.Fatal("overlapped unsettled resource effect") } old := a.Effects["one"] old.State = "complete" a.Effects["one"] = old if err := prepareEffect(&a, e); err != nil { t.Fatal(err) } } func TestRegistrationOwnerDeadlineMargin(t *testing.T) { now := time.Date(2026, 10, 7, 0, 0, 0, 0, time.UTC) r := Registration{Expires: now.Add(90 * time.Second)} if !RegistrationLive(r, now.Add(84*time.Second)) { t.Fatal("prematurely stopped") } if RegistrationLive(r, now.Add(85*time.Second)) { t.Fatal("issued inside margin") } if RegistrationDrained(r, now.Add(94*time.Second)) { t.Fatal("drained too early") } if !RegistrationDrained(r, now.Add(95*time.Second)) { t.Fatal("expiry grace did not end") } }