feat: upload audio, get a private Swedish transcript, discuss it (#33, ADR-033) #39
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user