carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package hostops
2
3import (
4 "testing"
5 "time"
6)
7
8func TestAdmissionRegistrationCannotRevive(t *testing.T) {
9 now := time.Date(2026, 10, 7, 0, 0, 0, 0, time.UTC)
10 owner := RegistrationOwner{Console: "console", Enrollment: "enrollment", Controller: "request"}
11 a := AppAdmission{V: 1, AppID: "app", Revision: 1, Epoch: 1, State: "open", Registrations: map[string]Registration{}, Effects: map[string]Effect{}}
12 r := Registration{Kind: "create", Host: "x.example", Owner: owner, AppID: "app", Epoch: 1, Claim: SavedClaim{Absent: true}}
13 if err := registerStart(&a, "operation", r, now); err != nil {
14 t.Fatal(err)
15 }
16 if got := a.Registrations["operation"].Expires; !got.Equal(now.Add(90 * time.Second)) {
17 t.Fatal(got)
18 }
19 a.State = "closed"
20 if err := renewStart(&a, "operation", owner, now.Add(20*time.Second)); err != nil {
21 t.Fatal(err)
22 }
23 if err := renewStart(&a, "operation", owner, now.Add(110*time.Second)); err == nil {
24 t.Fatal("revived expired registration")
25 }
26 delete(a.Registrations, "operation")
27 if err := renewStart(&a, "operation", owner, now.Add(40*time.Second)); err == nil {
28 t.Fatal("recreated missing registration")
29 }
30}
31
32func TestAdmissionEffectsDoNotExpireWithRegistration(t *testing.T) {
33 a := AppAdmission{V: 1, AppID: "app", Revision: 1, Epoch: 1, State: "open", Registrations: map[string]Registration{}, Effects: map[string]Effect{}}
34 e := Effect{ID: "one", OperationID: "op", AppID: "app", Resource: "store:environment", Action: "grant", State: "prepared", Owner: RegistrationOwner{Console: "console", Enrollment: "enrollment", Controller: "request"}}
35 if err := prepareEffect(&a, e); err != nil {
36 t.Fatal(err)
37 }
38 e.ID = "two"
39 if err := prepareEffect(&a, e); err == nil {
40 t.Fatal("overlapped unsettled resource effect")
41 }
42 old := a.Effects["one"]
43 old.State = "complete"
44 a.Effects["one"] = old
45 if err := prepareEffect(&a, e); err != nil {
46 t.Fatal(err)
47 }
48}
49
50func TestRegistrationOwnerDeadlineMargin(t *testing.T) {
51 now := time.Date(2026, 10, 7, 0, 0, 0, 0, time.UTC)
52 r := Registration{Expires: now.Add(90 * time.Second)}
53 if !RegistrationLive(r, now.Add(84*time.Second)) {
54 t.Fatal("prematurely stopped")
55 }
56 if RegistrationLive(r, now.Add(85*time.Second)) {
57 t.Fatal("issued inside margin")
58 }
59 if RegistrationDrained(r, now.Add(94*time.Second)) {
60 t.Fatal("drained too early")
61 }
62 if !RegistrationDrained(r, now.Add(95*time.Second)) {
63 t.Fatal("expiry grace did not end")
64 }
65}
66