From 64012d6c8aeb054dfa70b04472f01bf41a4bd3b8 Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Sat, 17 Oct 2026 04:54:13 +0200 Subject: [PATCH] test(aws/ladder): distinguish pre-write aborts during loopback fixture cleanup The scheduled CE loopback fixture cleanup always joined the handler and the real WroteRequest callback. A request that fails before any connection is dialed (dial error, guard rejection) starts neither, so the failed test also reported two watchdog errors after about ten seconds, on top of the real primary error. Track whether the handler started and whether a connection was dialed. Cleanup now joins the handler only if it started and the write callback only if a connection exists, and logs when the request never reached the wire. The write channel is never closed on the callback's behalf, so a real write completion and its error still count on the success path. Closes #417 Co-Authored-By: Claude Opus 5.5 --- providers/aws/ladder/ce_loopback_body_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/providers/aws/ladder/ce_loopback_body_test.go b/providers/aws/ladder/ce_loopback_body_test.go index e997e450..40644b53 100644 --- a/providers/aws/ladder/ce_loopback_body_test.go +++ b/providers/aws/ladder/ce_loopback_body_test.go @@ -194,7 +194,7 @@ func ceAwait(done, abort <-chan struct{}) error { type ceSchedule struct { abort, entered, sdkClosed, wrote, connClosed chan struct{} enterOnce, sdkOnce, writeOnce, connOnce sync.Once - returned atomic.Bool + returned, dialed, handlerStarted atomic.Bool copyErr, writeErr error status int } @@ -294,6 +294,7 @@ func TestCELoopbackPublicBaselineAfterBodyClose(t *testing.T) { var baseline ladder.UsageBaseline srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { defer close(handlerDone) + s.handlerStarted.Store(true) var input costexplorer.GetCostAndUsageInput handlerErr = json.NewDecoder(req.Body).Decode(&input) if handlerErr != nil { @@ -318,12 +319,22 @@ func TestCELoopbackPublicBaselineAfterBodyClose(t *testing.T) { if err != nil { return conn, err } + s.dialed.Store(true) return &ceScheduledConn{TCPConn: conn.(*net.TCPConn), s: s}, nil } cleanup := sync.OnceFunc(func() { cancel() close(s.abort) - opJoin, handlerJoin, writeJoin := ceAwait(done, nil), ceAwait(handlerDone, nil), ceAwait(s.wrote, nil) + opJoin := ceAwait(done, nil) + var handlerJoin, writeJoin error + if s.handlerStarted.Load() { + handlerJoin = ceAwait(handlerDone, nil) + } + if s.dialed.Load() { + writeJoin = ceAwait(s.wrote, nil) + } else { + t.Log("request aborted before any connection was dialed; skipping write and handler joins") + } if handlerJoin == nil { srv.Close() } else {