From 12d1365607f54655a39c2ec8331698bae3cb83a7 Mon Sep 17 00:00:00 2001 From: Mathias Date: Fri, 2 Oct 2026 17:47:13 +0200 Subject: [PATCH] test(web): the 499 test cancels the client mid-Accept, as a real hang-up does Co-Authored-By: Claude Sonnet 5.5 --- internal/web/uploads_disconnect_handler_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/web/uploads_disconnect_handler_test.go b/internal/web/uploads_disconnect_handler_test.go index b26ea5b..a5adb69 100644 --- a/internal/web/uploads_disconnect_handler_test.go +++ b/internal/web/uploads_disconnect_handler_test.go @@ -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) { // 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 @@ -88,12 +97,11 @@ func TestUploadPost_AnAbandonedRequestGetsA499NotAnImplicitEmpty200(t *testing.T app, _ := newUploadApp(t, audioOK, 200<<20) buf := &lockedBuf{} app.Log = slog.New(slog.NewTextHandler(buf, nil)) - app.Uploads = failingUploader{err: fmt.Errorf("receive: %w", io.ErrClosedPipe)} ctx, cancel := context.WithCancel(context.Background()) - cancel() - req := uploadReq(t, "t", "a.m4a", []byte("x")).WithContext(ctx) + defer cancel() + 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.Contains(t, buf.String(), "upload abandoned")