carlos / platform Public

edge test: the stream-life backhaul test signals once and reads the end (#358)

TestBackhaulSlotHeldForStreamLife's handler closed its streaming channel
on every request it served, so the third request, after the stream had
ended, panicked on a second close. The headers were already flushed and
the test checked only the status, so it passed over the panic.

The signal is now one-shot (sync.Once), and the third request's body
must arrive whole.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 6526925fd7fb3b79f62e40e94c97f46415f7c472 parent a4a4897
1 file changed, +10 −1
  • internal/edge/homemap_test.go +10 −1
diff --git a/internal/edge/homemap_test.go b/internal/edge/homemap_test.go
index 2e38542e8..e5d9ef0fe 100644
--- a/internal/edge/homemap_test.go
+++ b/internal/edge/homemap_test.go
@@ -1390,10 +1390,13 @@ func TestBackhaulSlotHeldForStreamLife(t *testing.T) {
backhaulCap(t, 1)
streaming, finish := make(chan struct{}), make(chan struct{})
+ // Every admitted request runs this handler, the last one too, so the
+ // signal is one-shot: a second close would panic that request's handler.
+ var streamingOnce sync.Once
_, eip := fakeHomeEdge(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "first ")
w.(http.Flusher).Flush() // headers and a first chunk are on the wire
- close(streaming)
+ streamingOnce.Do(func() { close(streaming) })
<-finish
fmt.Fprint(w, "last")
}))
@@ -1443,6 +1446,12 @@ func TestBackhaulSlotHeldForStreamLife(t *testing.T) {
if after.StatusCode != http.StatusOK {
t.Fatalf("status = %d after the stream ended, want 200 — the slot must have been released", after.StatusCode)
}
+ // Headers are flushed before the handler goes on, so a status alone
+ // would pass over a handler that died mid-answer: the body must finish.
+ body, err = io.ReadAll(after.Body)
+ if err != nil || string(body) != "first last" {
+ t.Fatalf("third body = %q (%v), want the whole answer", body, err)
+ }
}
// Saturation is one throttled journal line per home box, never silence and