test(web): the 499 test cancels the client mid-Accept, as a real hang-up does
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user