test(web): the 499 test cancels the client mid-Accept, as a real hang-up does
CI / Lint / Test / Vet (pull_request) Successful in 27s
CI / Build & Import (pull_request) Skipped
CI / Deploy via GitOps (pull_request) Skipped

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-02 17:47:13 +02:00
co-authored by Claude Sonnet 5.5
parent 9d7afb2bcb
commit 12d1365607
@@ -81,6 +81,15 @@ func TestUploadPost_AClientThatHangsUpAnywhereInTheBodyIsLoggedAtInfoAndNeverAsA
} }
} }
// goneMidAccept is an Uploader during whose Accept the client disappears: the request's
// context is cancelled, then Accept fails the way a read from a dead connection does.
type goneMidAccept struct{ cancel context.CancelFunc }
func (g goneMidAccept) Accept(context.Context, string, string, io.Reader) (string, error) {
g.cancel()
return "", fmt.Errorf("receive: %w", io.ErrClosedPipe)
}
func TestUploadPost_AnAbandonedRequestGetsA499NotAnImplicitEmpty200(t *testing.T) { func TestUploadPost_AnAbandonedRequestGetsA499NotAnImplicitEmpty200(t *testing.T) {
// If the context is cancelled but the connection can still be written to (a client that // If the context is cancelled but the connection can still be written to (a client that
// half-closed after sending), a missing status becomes 200 with an empty body: a false // half-closed after sending), a missing status becomes 200 with an empty body: a false
@@ -88,12 +97,11 @@ func TestUploadPost_AnAbandonedRequestGetsA499NotAnImplicitEmpty200(t *testing.T
app, _ := newUploadApp(t, audioOK, 200<<20) app, _ := newUploadApp(t, audioOK, 200<<20)
buf := &lockedBuf{} buf := &lockedBuf{}
app.Log = slog.New(slog.NewTextHandler(buf, nil)) app.Log = slog.New(slog.NewTextHandler(buf, nil))
app.Uploads = failingUploader{err: fmt.Errorf("receive: %w", io.ErrClosedPipe)}
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
cancel() defer cancel()
req := uploadReq(t, "t", "a.m4a", []byte("x")).WithContext(ctx) app.Uploads = goneMidAccept{cancel: cancel}
rec := do(t, app, req) rec := do(t, app, uploadReq(t, "t", "a.m4a", []byte("x")).WithContext(ctx))
assert.Equal(t, 499, rec.Code, "never an implicit 200 for an upload that was not accepted") assert.Equal(t, 499, rec.Code, "never an implicit 200 for an upload that was not accepted")
assert.Contains(t, buf.String(), "upload abandoned") assert.Contains(t, buf.String(), "upload abandoned")