| index 2d8862483..15d522cf4 100644 |
| --- a/internal/host/hatakeover_wiring_test.go |
| +++ b/internal/host/hatakeover_wiring_test.go |
| @@ -2,9 +2,14 @@ package host |
| |
| import ( |
| "context" |
| + "io" |
| + "net/http" |
| + "net/http/httptest" |
| "os" |
| "strings" |
| + "sync/atomic" |
| "testing" |
| + "time" |
| |
| "github.com/carlosframework/platform/internal/boxid" |
| "github.com/carlosframework/platform/internal/hafresh" |
| @@ -55,3 +60,46 @@ func TestHAOwnerConfirmerReadsTheLateIdentity(t *testing.T) { |
| t.Fatal("no EC2 client builder") |
| } |
| } |
| + |
| +// The oracle's describe is one HTTP request, not the SDK's three: the |
| +// confirmer's ten-second negative cache is the only retry. The client is the |
| +// production-built one, aimed at a server that answers 503. |
| +func TestHAOwnerConfirmerDescribeIsOneRequest(t *testing.T) { |
| + t.Cleanup(lease.ProcessStateForTest()) |
| + var requests atomic.Int32 |
| + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + requests.Add(1) |
| + w.WriteHeader(http.StatusServiceUnavailable) |
| + io.WriteString(w, `<Response><Errors><Error><Code>RequestLimitExceeded</Code><Message>slow down</Message></Error></Errors><RequestID>req-1</RequestID></Response>`) |
| + })) |
| + defer srv.Close() |
| + t.Setenv("AWS_ENDPOINT_URL_EC2", srv.URL) |
| + t.Setenv("AWS_ACCESS_KEY_ID", "AKIDEXAMPLE") |
| + t.Setenv("AWS_SECRET_ACCESS_KEY", "secret") |
| + t.Setenv("AWS_SESSION_TOKEN", "") |
| + t.Setenv("AWS_PROFILE", "") |
| + t.Setenv("AWS_EC2_METADATA_DISABLED", "true") |
| + lease.SetSelf(hafresh.Self{Ref: "a", IID: "i-a", Account: "111122223333", Region: "eu-west-1"}) |
| + |
| + now := time.Date(2026, 10, 27, 12, 0, 0, 0, time.UTC) |
| + c := haOwnerConfirmer() |
| + c.Now = func() time.Time { return now } |
| + c.Logf = func(string, ...any) {} |
| + |
| + if yes, err := c.Terminated(context.Background(), "i-b"); yes || err == nil { |
| + t.Fatalf("a throttled describe answered %v, %v", yes, err) |
| + } |
| + if got := requests.Load(); got != 1 { |
| + t.Fatalf("the first call made %d requests, want 1 (the SDK retried)", got) |
| + } |
| + now = now.Add(termfence.ConfirmNegativeTTL - time.Second) |
| + c.Terminated(context.Background(), "i-b") |
| + if got := requests.Load(); got != 1 { |
| + t.Fatalf("inside the negative cache: %d requests, want 1", got) |
| + } |
| + now = now.Add(2 * time.Second) |
| + c.Terminated(context.Background(), "i-b") |
| + if got := requests.Load(); got != 2 { |
| + t.Fatalf("after the negative cache: %d requests, want 2", got) |
| + } |
| +} |