carlos / platform Public

test: probe LB health like the load balancer in the loss witness

Co-Authored-By: GPT-6 Astra <noreply@openai.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev cecbac3615c599fe034830fc5a7b186676253b7b parent 534ff3c
6 files changed, +95 −3
  • internal/host/region_ha_g2_loss_helpers_test.go +31 −0
  • internal/host/region_ha_g2_loss_root_linux_test.go +22 −1
  • scripts/region-ha-g2-loss-witness.py +3 −1
  • scripts/region-ha-g2-pool-witness.py +4 −0
  • scripts/region_ha_g2_bytecode_witness_test.py +31 −0
  • scripts/region_ha_g2_witness.py +4 −1

Intent

Human

<task-notification> <task-id>bi2uqfk84</task-id> <tool-use-id>toolu_01QENhDMuYsEFtoURVC39bmP</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/5555438b-7fa2-408d-b2c4-9fa87ea89332/tasks/bi2uqfk84.output</output-file> <status>completed</status> <summary>Background command "Run F-A witness live, run 2" 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 d141c5fb5..b76c456ad 100644
--- a/internal/host/region_ha_g2_loss_helpers_test.go
+++ b/internal/host/region_ha_g2_loss_helpers_test.go
@@ -8,6 +8,7 @@ import (
"fmt"
"net"
"net/http"
+ "net/http/httptest"
"os"
"os/exec"
"path/filepath"
@@ -16,6 +17,36 @@ import (
"time"
)
+func TestG2LossLBHealthRequest(t *testing.T) {
+ const ip = "10.0.0.2"
+ for _, status := range []int{http.StatusOK, http.StatusServiceUnavailable, http.StatusFound} {
+ t.Run(http.StatusText(status), func(t *testing.T) {
+ requests := 0
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ requests++
+ if r.Method != http.MethodGet || r.Host != ip || r.URL.Path != "/.carlos/lb-health" || r.TLS != nil {
+ t.Errorf("not an NLB health request: method=%s host=%s url=%s tls=%v", r.Method, r.Host, r.URL, r.TLS)
+ }
+ w.Header().Set("Location", "/tenant")
+ w.WriteHeader(status)
+ _, _ = w.Write([]byte("health"))
+ }))
+ defer server.Close()
+ transport := &http.Transport{DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
+ if address != net.JoinHostPort(ip, "80") {
+ t.Errorf("health dial=%s, want %s:80", address, ip)
+ }
+ return (&net.Dialer{}).DialContext(ctx, network, server.Listener.Addr().String())
+ }}
+ defer transport.CloseIdleConnections()
+ response := g2LossLBHealth(t.Context(), &http.Client{Transport: transport}, ip)
+ if response.Err != nil || response.Status != status || string(response.Body) != "health" || requests != 1 {
+ t.Fatalf("health response=%+v requests=%d", response, requests)
+ }
+ })
+ }
+}
+
func TestG2LossLatencyAssertion(t *testing.T) {
response := g2Response{Status: 503, Headers: http.Header{"Retry-After": {"10"}, "X-Carlos-Holder": {"none"}}, Body: []byte(g2C1Body), Elapsed: time.Millisecond}
if err := g2LossRefusal(response); err != nil {
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 fca39fdf1..3407c8c82 100644
--- a/internal/host/region_ha_g2_loss_root_linux_test.go
+++ b/internal/host/region_ha_g2_loss_root_linux_test.go
@@ -119,6 +119,26 @@ func g2LossRequest(ctx context.Context, client *http.Client, host, path, method,
body, err := io.ReadAll(io.LimitReader(response.Body, 1<<20))
return g2Response{Status: response.StatusCode, Headers: response.Header.Clone(), Body: body, Err: err, Elapsed: time.Since(started)}
}
+
+func g2LossLBHealth(ctx context.Context, client *http.Client, ip string) g2Response {
+ started := time.Now()
+ request, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://"+net.JoinHostPort(ip, "80")+"/.carlos/lb-health", nil)
+ if err != nil {
+ return g2Response{Err: err}
+ }
+ request.Host = ip
+ probe := *client
+ probe.Timeout = 2 * time.Second
+ probe.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }
+ response, err := probe.Do(request)
+ if err != nil {
+ return g2Response{Err: err, Elapsed: time.Since(started)}
+ }
+ defer response.Body.Close()
+ body, err := io.ReadAll(io.LimitReader(response.Body, 1<<20))
+ return g2Response{Status: response.StatusCode, Headers: response.Header.Clone(), Body: body, Err: err, Elapsed: time.Since(started)}
+}
+
func g2LossReads(events []g2S3Event, source, host string, since time.Time) int {
count := 0
for _, event := range events {
@@ -326,7 +346,8 @@ 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")
- health := g2LossRequest(t.Context(), direct, g2Host, "/.carlos/lb-health", "GET", "")
+ healthClient := &http.Client{Transport: &http.Transport{DisableKeepAlives: true}}
+ health := g2LossLBHealth(t.Context(), healthClient, os.Getenv("G2_B_IP"))
g2LogResponse(t, "lb-health", health)
if health.Err != nil || health.Status != 200 {
t.Fatal("LB health changed during lease loss")
diff --git a/scripts/region-ha-g2-loss-witness.py b/scripts/region-ha-g2-loss-witness.py
index 7b4382007..aadda48b1 100755
--- a/scripts/region-ha-g2-loss-witness.py
+++ b/scripts/region-ha-g2-loss-witness.py
@@ -1,8 +1,10 @@
#!/usr/bin/env python3
"""Task 11 controller; --dry-run makes zero AWS calls."""
-import json
import sys
+sys.dont_write_bytecode = True
+
+import json
import region_ha_g2_witness as shared
PASS = "PASS TestRootG2LostLeaseResponses"
diff --git a/scripts/region-ha-g2-pool-witness.py b/scripts/region-ha-g2-pool-witness.py
index 07c04dff2..230130077 100644
--- a/scripts/region-ha-g2-pool-witness.py
+++ b/scripts/region-ha-g2-pool-witness.py
@@ -1,5 +1,9 @@
#!/usr/bin/env python3
"""Task 10 controller; --dry-run makes zero AWS calls."""
+import sys
+
+sys.dont_write_bytecode = True
+
from region_ha_g2_witness import *
if __name__ == "__main__":
diff --git a/scripts/region_ha_g2_bytecode_witness_test.py b/scripts/region_ha_g2_bytecode_witness_test.py
new file mode 100644
index 000000000..ff1df1854
--- /dev/null
+++ b/scripts/region_ha_g2_bytecode_witness_test.py
@@ -0,0 +1,31 @@
+import os
+from pathlib import Path
+import shutil
+import subprocess
+import sys
+import tempfile
+import unittest
+
+
+class WitnessBytecodeTest(unittest.TestCase):
+ def test_entry_points_do_not_write_bytecode(self):
+ scripts = Path(__file__).resolve().parent
+ files = ("region-ha-g2-pool-witness.py", "region-ha-g2-loss-witness.py",
+ "region_ha_g2_witness.py")
+ for entry in files:
+ with self.subTest(entry=entry), tempfile.TemporaryDirectory(dir=os.environ["TMPDIR"]) as directory:
+ root = Path(directory)
+ for name in files:
+ shutil.copyfile(scripts / name, root / name)
+ # -E ignores inherited Python bytecode settings; the script must protect itself.
+ result = subprocess.run(
+ [sys.executable, "-E", str(root / entry), "--dry-run",
+ "--worktree", str(root), "--expected-tip", "a" * 40,
+ "--evidence-dir", str(root / "evidence")],
+ cwd=root, capture_output=True, text=True, timeout=30, check=True)
+ self.assertIn("DRY RUN ONLY: zero AWS calls, no acceptance claimed", result.stdout)
+ self.assertEqual(sorted(path.name for path in root.iterdir()), sorted(files))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/scripts/region_ha_g2_witness.py b/scripts/region_ha_g2_witness.py
index 6b4f7cd99..d697998fa 100644
--- a/scripts/region_ha_g2_witness.py
+++ b/scripts/region_ha_g2_witness.py
@@ -1,5 +1,9 @@
#!/usr/bin/env python3
"""Shared disposable-runner lifecycle for the G2 witnesses."""
+import sys
+
+sys.dont_write_bytecode = True
+
import argparse
import datetime as dt
import hashlib
@@ -11,7 +15,6 @@ import shlex
import shutil
import signal
import subprocess
-import sys
import tempfile
import time
import urllib.request