edge test: a cancelled alias upload may end in the edge's refusal
TestDemoAPIAliasStreaming/h2=false/ingress=1/cancel failed on CI with "cancel succeeded". When the client cancels, the edge's upstream request breaks and the edge answers 503, the refusal the drop case also gets. That 503 can reach the client before its Transport acts on the cancel, and Transport may then return the response instead of the cancellation. Seen on DOCS-T1 under load (status=503, empty body), 2 in 160 runs. The test now fails only if a cancelled upload gets anything other than the cancellation or that refusal: 0 in 300.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+15
−5
internal/edge/demo_api_integration_test.go+15 −5
CI passed — run details
diff --git a/internal/edge/demo_api_integration_test.go b/internal/edge/demo_api_integration_test.go| index 68cac3fdd..b36551e0a 100644 |
| --- a/internal/edge/demo_api_integration_test.go |
| +++ b/internal/edge/demo_api_integration_test.go |
| @@ -369,13 +369,23 @@ func TestDemoAPIAliasStreaming(t *testing.T) { |
| defer cancel() |
| req, _ := http.NewRequestWithContext(ctx, "POST", origin+"/api/demo/apps", pr) |
| req.Header.Set("X-Carlos-Client", "cancel") |
| - done := make(chan error, 1) |
| + // A cancelled upload never succeeds. Do returns the |
| + // cancellation, or the edge's refusal of the broken upload |
| + // when that response reached the client first: Transport |
| + // may return a response already in flight instead (#897). |
| + type answer struct { |
| + status int |
| + err error |
| + } |
| + done := make(chan answer, 1) |
| go func() { |
| resp, err := client.Do(req) |
| + a := answer{err: err} |
| if resp != nil { |
| + a.status = resp.StatusCode |
| resp.Body.Close() |
| } |
| - done <- err |
| + done <- a |
| }() |
| if _, err := pw.Write([]byte("x")); err != nil { |
| t.Fatal(err) |
| @@ -388,9 +398,9 @@ func TestDemoAPIAliasStreaming(t *testing.T) { |
| cancel() |
| pw.CloseWithError(context.Canceled) |
| select { |
| - case err := <-done: |
| - if err == nil { |
| - t.Fatal("cancel succeeded") |
| + case a := <-done: |
| + if a.err == nil && a.status != http.StatusServiceUnavailable { |
| + t.Fatalf("cancel succeeded: %d", a.status) |
| } |
| case <-time.After(3 * time.Second): |
| t.Fatal("client ignored cancellation") |