carlos / platform Public

test: measure suspect holders from lease expiry

Use an explicit simulated expiry one minute before the first refusal. Assert the count at expiry plus ten minutes, immediately before it, and after observation freshness expires.
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 534ff3c283c6adc5923669a4bf56f17a1983e7f9 parent e96fe63
1 file changed, +10 −7
  • internal/host/suspects_test.go +10 −7
diff --git a/internal/host/suspects_test.go b/internal/host/suspects_test.go
index 4c55bbd73..994739ad0 100644
--- a/internal/host/suspects_test.go
+++ b/internal/host/suspects_test.go
@@ -24,10 +24,7 @@ import (
func withSuspectMetricBackend(t *testing.T, check func(*testing.T, *activator.ExecBackend, time.Time)) {
t.Helper()
const host = "shop.example.com"
- body, err := json.Marshal(hafresh.Lock{Generation: 9, Owner: "box/v1;ref=b;iid=i-b;pid=7;ha=1", ExpiresAt: time.Unix(0, 0).UTC()})
- if err != nil {
- t.Fatal(err)
- }
+ var body atomic.Pointer[[]byte]
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Connection", "close")
if r.Method != http.MethodGet || r.URL.Path != "/locks/"+activator.HibernatePrefix("", host)+"/lock.json" {
@@ -36,7 +33,7 @@ func withSuspectMetricBackend(t *testing.T, check func(*testing.T, *activator.Ex
return
}
w.Header().Set("ETag", `"held-by-b"`)
- _, _ = w.Write(body)
+ _, _ = w.Write(*body.Load())
}))
t.Cleanup(srv.Close)
for k, v := range map[string]string{
@@ -53,6 +50,12 @@ func withSuspectMetricBackend(t *testing.T, check func(*testing.T, *activator.Ex
}
root := t.TempDir()
synctest.Test(t, func(t *testing.T) {
+ expiresAt := time.Now().Add(-time.Minute)
+ payload, err := json.Marshal(hafresh.Lock{Generation: 9, Owner: "box/v1;ref=b;iid=i-b;pid=7;ha=1", ExpiresAt: expiresAt})
+ if err != nil {
+ t.Fatal(err)
+ }
+ body.Store(&payload)
proofs := 0
b := &activator.ExecBackend{ServedPools: testSharedPoolEvidence,
Cfg: activator.Config{Bucket: "locks", Region: "eu-west-1"},
@@ -76,7 +79,7 @@ func withSuspectMetricBackend(t *testing.T, check func(*testing.T, *activator.Ex
}
}
refuse()
- time.Sleep(11 * time.Minute)
+ time.Sleep(9 * time.Minute)
refuse()
if proofs != 2 {
t.Fatalf("termination proof calls=%d, want 2", proofs)
@@ -96,7 +99,7 @@ func TestSuspectsFrom(t *testing.T) {
if got := count(now); got != 1 {
t.Fatalf("sustained refusal: count=%d, want 1", got)
}
- if got := count(now.Add(-2 * time.Minute)); got != 0 {
+ if got := count(now.Add(-time.Nanosecond)); got != 0 {
t.Fatalf("before ten minutes: count=%d, want 0", got)
}
if got := count(now.Add(5 * time.Minute)); got != 0 {