carlos / platform Public

test: count only lease recovery calls in the no-demand window

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev b2007cf9eccd10f7170a8ad0c0092ac385037d49 parent e40a828
2 files changed, +68 −8
  • internal/host/region_ha_g2_loss_helpers_test.go +40 −0
  • internal/host/region_ha_g2_loss_root_linux_test.go +28 −8

Intent

Human

<task-notification> <task-id>b9a503q53</task-id> <tool-use-id>toolu_01DcauJGbqnc32PrzdDhEjBS</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/b9a503q53.output</output-file> <status>completed</status> <summary>Background command "F-A witness run 10" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/host/region_ha_g2_loss_helpers_test.go b/internal/host/region_ha_g2_loss_helpers_test.go
index aac8dade4..8c6123507 100644
--- a/internal/host/region_ha_g2_loss_helpers_test.go
+++ b/internal/host/region_ha_g2_loss_helpers_test.go
@@ -280,6 +280,46 @@ func TestG2LossRequestCensus(t *testing.T) {
}
}
+func TestG2LossQuietCalls(t *testing.T) {
+ now := time.Now()
+ prefix := "/" + g2Data + "/instances/h/"
+ for _, tt := range []struct {
+ name, method, path, source string
+ at time.Time
+ release bool
+ status, attempts, reads int
+ }{
+ {"discovery", "GET", prefix + "lock.json", "peer", now, false, 200, 1, 0},
+ {"failed-discovery", "GET", prefix + "lock.json", "peer", now, false, 503, 1, 0},
+ {"unfinished-discovery", "GET", prefix + "lock.json", "peer", now, false, 0, 1, 0},
+ {"acquire", "PUT", prefix + "lock.json", "peer", now, false, 200, 1, 0},
+ {"refused-acquire", "PUT", prefix + "lock.json", "peer", now, false, 412, 1, 0},
+ {"owed-marker", "PUT", prefix + "lock.json", "peer", now, true, 0, 1, 0},
+ {"build-state-refresh", "GET", prefix + "build-state.json", "peer", now, false, 200, 0, 1},
+ {"files-read", "GET", prefix + "files/manifest.json", "peer", now, false, 0, 0, 1},
+ {"metadata-read", "HEAD", prefix + "build-state.json", "peer", now, false, 200, 0, 1},
+ {"instance-record", "GET", "/" + g2Deploy + "/apps/" + g2Account + "/" + g2App + "/instances/h.json", "peer", now, false, 200, 0, 1},
+ {"incarnation", "GET", "/" + g2Deploy + "/control/host-incarnations/h.json", "peer", now, false, 200, 0, 1},
+ {"other-host", "GET", "/" + g2Data + "/instances/h-other/lock.json", "peer", now, false, 200, 0, 0},
+ {"other-record", "GET", "/" + g2Deploy + "/control/host-incarnations/other-h.json", "peer", now, false, 200, 0, 0},
+ {"other-source", "PUT", prefix + "lock.json", "audit", now, false, 200, 0, 0},
+ {"other-source-read", "GET", prefix + "build-state.json", "audit", now, false, 200, 0, 0},
+ {"before-window", "GET", prefix + "lock.json", "peer", now.Add(-time.Nanosecond), false, 200, 0, 0},
+ {"read-before-window", "GET", prefix + "build-state.json", "peer", now.Add(-time.Nanosecond), false, 200, 0, 0},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ event := g2S3Event{At: tt.at, Source: tt.source, Method: tt.method, Path: tt.path, Release: tt.release, Status: tt.status}
+ attempts, reads := g2LossQuietCalls([]g2S3Event{event}, "peer", "h", now)
+ if attempts != tt.attempts || len(reads) != tt.reads {
+ t.Fatalf("attempts=%d other_reads=%d, want %d/%d", attempts, len(reads), tt.attempts, tt.reads)
+ }
+ if len(reads) != 0 && reads[0] != event {
+ t.Fatalf("read evidence changed: got %+v want %+v", reads[0], event)
+ }
+ })
+ }
+}
+
func TestG2LossSlowResponseTiming(t *testing.T) {
for _, tt := range []struct {
name string
diff --git a/internal/host/region_ha_g2_loss_root_linux_test.go b/internal/host/region_ha_g2_loss_root_linux_test.go
index ff0137b72..1d529dc20 100644
--- a/internal/host/region_ha_g2_loss_root_linux_test.go
+++ b/internal/host/region_ha_g2_loss_root_linux_test.go
@@ -169,6 +169,28 @@ func g2LossReads(events []g2S3Event, source, host string, since time.Time) int {
}
return count
}
+
+func g2LossQuietCalls(events []g2S3Event, source, host string, since time.Time) (int, []g2S3Event) {
+ prefix := "/" + g2Data + "/instances/" + host + "/"
+ attempts := 0
+ var otherReads []g2S3Event
+ for _, event := range events {
+ if event.Source != source || event.At.Before(since) {
+ continue
+ }
+ // Discovery reads the lock; acquisition and owed markers write it.
+ // Count arrivals even when the request fails or never completes.
+ if event.Path == prefix+"lock.json" && (event.Method == "GET" || event.Method == "PUT") {
+ attempts++
+ continue
+ }
+ if (event.Method == "GET" || event.Method == "HEAD") && (strings.HasPrefix(event.Path, prefix) || strings.HasSuffix(event.Path, "/"+host+".json")) {
+ otherReads = append(otherReads, event)
+ }
+ }
+ return attempts, otherReads
+}
+
func g2LossCheck(t *testing.T, client *http.Client, name string) {
t.Helper()
ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second)
@@ -648,7 +670,7 @@ func g2LossNoDemand(t *testing.T, storage *g2Storage, audit release.Store, a *g2
g2Stopped(t, g2Peer(t, g2RPC{Action: "thaw"}), g2Host)
frozen = false
// One request provides demand. The latched B host discovers the real A
- // lease and then must make no more per-host S3 calls without another request.
+ // lease and then must make no more lease-recovery calls without another request.
start := time.Now()
g2LossCheck(t, direct, "foreign-discovery-demand")
t.Log("FROZEN_HOLDER_REFUSAL basis=holder-own-C1-after-pause-loss-and-resume")
@@ -660,20 +682,18 @@ func g2LossNoDemand(t *testing.T, storage *g2Storage, audit release.Store, a *g2
time.Sleep(250 * time.Millisecond)
quiet := time.Now()
time.Sleep(65 * time.Second)
- attempts := 0
storage.loss.mu.Lock()
arrivals := slices.Clone(storage.loss.arrivals)
storage.loss.mu.Unlock()
- for _, event := range arrivals {
- if event.Source == os.Getenv("G2_B_IP") && !event.At.Before(quiet) && strings.HasPrefix(event.Path, "/"+g2Data+"/instances/"+g2Host+"/") {
- attempts++
- }
+ attempts, otherReads := g2LossQuietCalls(arrivals, os.Getenv("G2_B_IP"), g2Host, quiet)
+ for _, event := range otherReads {
+ t.Logf("NO_DEMAND_OTHER_HOST_READ method=%s path=%s at=%s", event.Method, event.Path, event.At.UTC().Format(time.RFC3339Nano))
}
reads := g2LossReads(storage.snapshot(), os.Getenv("G2_B_IP"), g2Host, start)
if attempts != 0 || reads != 1 {
- t.Fatalf("no-demand foreign holder: first_attempt_reads=%d later_s3_calls=%d", reads, attempts)
+ t.Fatalf("no-demand foreign holder: first_attempt_reads=%d later_s3_calls=%d counter_scope=lease-recovery", reads, attempts)
}
- t.Logf("CASE no-demand-no-s3 PASS scope=completed-stop first_attempt_reads=%d later_s3_calls=%d window=65s", reads, attempts)
+ t.Logf("CASE no-demand-no-s3 PASS scope=completed-stop first_attempt_reads=%d later_s3_calls=%d counter_scope=lease-recovery other_host_reads=%d window=65s", reads, attempts, len(otherReads))
delivery := g2Served(t, direct, "foreign-holder-http-recovery", g2Host, self, func() { g2Stopped(t, g2Peer(t, g2RPC{Action: "state"}), g2Host) })
g2Stopped(t, g2Peer(t, g2RPC{Action: "state"}), g2Host)
if delivery.Deliveries[g2LossNewHolderID] != 1 {