test: assert LB health is unchanged by lease loss
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
2 files changed,
+43
−6
internal/host/region_ha_g2_loss_helpers_test.go+28 −0internal/host/region_ha_g2_loss_root_linux_test.go+15 −6
CI passed — run details
diff --git a/internal/host/region_ha_g2_loss_helpers_test.go b/internal/host/region_ha_g2_loss_helpers_test.go| index f7c34b99e..cba81eb6d 100644 |
| --- a/internal/host/region_ha_g2_loss_helpers_test.go |
| +++ b/internal/host/region_ha_g2_loss_helpers_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "context" |
| "database/sql" |
| "fmt" |
| + "io" |
| "net" |
| "net/http" |
| "net/http/httptest" |
| @@ -47,6 +48,33 @@ func TestG2LossLBHealthRequest(t *testing.T) { |
| } |
| } |
| +func TestG2LossLBHealthUnchanged(t *testing.T) { |
| + healthy := g2Response{Status: http.StatusOK, Body: []byte("ok\n")} |
| + hosting := g2Response{Status: http.StatusServiceUnavailable, Body: []byte("unavailable: hosting\n")} |
| + for _, tt := range []struct { |
| + name string |
| + before, during g2Response |
| + wantErr bool |
| + }{ |
| + {"healthy", healthy, healthy, false}, |
| + {"hosting-before-and-during-loss", hosting, hosting, false}, |
| + {"status-changed", healthy, g2Response{Status: http.StatusServiceUnavailable, Body: healthy.Body}, true}, |
| + {"status-improved", hosting, g2Response{Status: http.StatusOK, Body: hosting.Body}, true}, |
| + {"body-changed", healthy, g2Response{Status: http.StatusOK, Body: []byte("unavailable: hosting\n")}, true}, |
| + {"condition-changed", hosting, g2Response{Status: http.StatusServiceUnavailable, Body: []byte("unavailable: draining\n")}, true}, |
| + {"body-whitespace-changed", healthy, g2Response{Status: http.StatusOK, Body: []byte("ok")}, true}, |
| + {"baseline-read-error", g2Response{Status: http.StatusOK, Body: healthy.Body, Err: io.ErrUnexpectedEOF}, healthy, true}, |
| + {"loss-read-error", healthy, g2Response{Status: http.StatusOK, Body: healthy.Body, Err: io.ErrUnexpectedEOF}, true}, |
| + {"both-transport-errors", g2Response{Err: context.DeadlineExceeded}, g2Response{Err: context.DeadlineExceeded}, true}, |
| + } { |
| + t.Run(tt.name, func(t *testing.T) { |
| + if err := g2LossLBHealthUnchanged(tt.before, tt.during); (err != nil) != tt.wantErr { |
| + t.Fatalf("before=%+v during=%+v error=%v wantErr=%v", tt.before, tt.during, err, tt.wantErr) |
| + } |
| + }) |
| + } |
| +} |
| + |
| func TestG2LossRenewalTiming(t *testing.T) { |
| start := time.Now() |
| for _, tt := range []struct { |
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 a81e68458..f0e69a837 100644 |
| --- a/internal/host/region_ha_g2_loss_root_linux_test.go |
| +++ b/internal/host/region_ha_g2_loss_root_linux_test.go |
| @@ -153,6 +153,13 @@ func g2LossLBHealth(ctx context.Context, client *http.Client, ip string) g2Respo |
| return g2Response{Status: response.StatusCode, Headers: response.Header.Clone(), Body: body, Err: err, Elapsed: time.Since(started)} |
| } |
| +func g2LossLBHealthUnchanged(before, during g2Response) error { |
| + if before.Err != nil || during.Err != nil || before.Status != during.Status || !slices.Equal(before.Body, during.Body) { |
| + return fmt.Errorf("LB health changed during lease loss: before_status=%d before_body=%q before_error=%v during_status=%d during_body=%q during_error=%v", before.Status, before.Body, before.Err, during.Status, during.Body, during.Err) |
| + } |
| + return nil |
| +} |
| + |
| func g2LossReads(events []g2S3Event, source, host string, since time.Time) int { |
| count := 0 |
| for _, event := range events { |
| @@ -329,6 +336,11 @@ func TestRootG2LostLeaseResponses(t *testing.T) { |
| if left := time.Until(initial.Lock.ExpiresAt); left < 14*time.Minute || left > lease.LeaseTTL { |
| t.Fatalf("production TTL changed: remaining=%s ttl=%s", left, lease.LeaseTTL) |
| } |
| + healthIP := os.Getenv("G2_B_IP") |
| + healthClient := &http.Client{Transport: &http.Transport{DisableKeepAlives: true}} |
| + beforeHealth := g2LossLBHealth(t.Context(), healthClient, healthIP) |
| + g2LogResponse(t, "lb-health-before-fault", beforeHealth) |
| + g2Must(t, beforeHealth.Err) |
| // Root control is stopped only after both production isolation verdicts. |
| // The edge and HTTP peer remain live, so loss must refuse before stop finishes. |
| cursor := g2Peer(t, g2RPC{Action: "journal-cursor"}).AgentJournal |
| @@ -376,13 +388,10 @@ func TestRootG2LostLeaseResponses(t *testing.T) { |
| t.Fatal("holder-none did not drop cache and rediscover") |
| } |
| t.Log("CASE holder-none-cache-drop PASS lock_reads=1") |
| - healthClient := &http.Client{Transport: &http.Transport{DisableKeepAlives: true}} |
| - health := g2LossLBHealth(t.Context(), healthClient, os.Getenv("G2_B_IP")) |
| + health := g2LossLBHealth(t.Context(), healthClient, healthIP) |
| g2LogResponse(t, "lb-health", health) |
| - if health.Err != nil || health.Status != 200 { |
| - t.Fatal("LB health changed during lease loss") |
| - } |
| - t.Log("CASE lb-health PASS") |
| + g2Must(t, g2LossLBHealthUnchanged(beforeHealth, health)) |
| + t.Logf("CASE lb-health PASS ip=%s port=80 before_status=%d before_body=%q during_status=%d during_body=%q", healthIP, beforeHealth.Status, beforeHealth.Body, health.Status, health.Body) |
| g2Stopped(t, a.state(), g2Host) |
| if err := g2ZeroAcquire(storage.snapshot(), os.Getenv("G2_A_IP"), g2Host); err != nil { |
| t.Fatal(err) |