diff --git a/internal/uploads/intake_busy_test.go b/internal/uploads/intake_busy_test.go index 6f12519..0b0cf22 100644 --- a/internal/uploads/intake_busy_test.go +++ b/internal/uploads/intake_busy_test.go @@ -3,6 +3,8 @@ package uploads_test import ( "context" "errors" + "fmt" + "io" "strings" "testing" "time" @@ -64,3 +66,31 @@ func TestAccept_ASubmitterThatCannotSayStillWorksAsBefore(t *testing.T) { require.NoError(t, err, "a Submitter without HasRoom is accepted: the check at Submit remains") } + +// brokenBody is a client body that fails mid-read, like a connection that dropped. +type brokenBody struct{ n int } + +func (b *brokenBody) Read(p []byte) (int, error) { + if b.n > 0 { + b.n = 0 + return copy(p, "partial audio"), nil + } + return 0, io.ErrUnexpectedEOF +} + +func TestAccept_AnErrorReadingTheClientsBodyIsMarkedAsTheClientsAndNothingElseIs(t *testing.T) { + r := newRig(t) + + _, err := r.in.Accept(context.Background(), "user-1", "t", &brokenBody{n: 1}) + + require.Error(t, err) + assert.ErrorIs(t, err, uploads.ErrClientRead, "a dropped client body is the sender's to retry") + assert.Empty(t, r.tmpFiles(t)) + + // A fault that is ours must NOT carry the marker, even if it wraps the same sentinel. + r2 := newRig(t) + r2.sub.err = fmt.Errorf("db: %w", io.ErrUnexpectedEOF) + _, err = r2.in.Accept(context.Background(), "user-1", "t", strings.NewReader("data")) + require.Error(t, err) + assert.NotErrorIs(t, err, uploads.ErrClientRead) +}