Skip to content

Commit

Permalink
Fix EOF not triggering a clean of the final output
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Sep 13, 2023
1 parent 3fc7d6b commit d728543
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions outputproducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func (o *outputProducer) processNextRead(r io.Reader, w io.Writer, appendBuffer
if _, err := w.Write(snapshot[:n]); err != nil {
return fmt.Errorf("could not write: %w", err)
}
}

if n > 0 || isEOF {
if err := appendBuffer(snapshot[:n], isEOF); err != nil {
return fmt.Errorf("could not append buffer: %w", err)
}
Expand Down
15 changes: 13 additions & 2 deletions outputproducer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Test_outputProducer_listen(t *testing.T) {
{[]byte("Three"), chunkInterval},
},
},
[]string{"One", "Two", "Three"},
[]string{"One", "Two", "Three", ""}, // Last append is EOF and should ALWAYS happen
nil,
},
{
Expand All @@ -48,7 +48,18 @@ func Test_outputProducer_listen(t *testing.T) {
{[]byte(valExceedBuff), chunkInterval},
},
},
[]string{valExceedBuff[:bufferSize], valExceedBuff[bufferSize:]},
[]string{valExceedBuff[:bufferSize], valExceedBuff[bufferSize:], ""}, // Last append is EOF and should ALWAYS happen
nil,
},
{
"EOF should trigger an append, even if new output is empty",
func(t *testing.T) *outputProducer { return newOutputProducer(newTestOpts(nil, t)) },
&readTester{
[]readTesterChunk{
{[]byte("foo"), chunkInterval},
},
},
[]string{"foo", ""},
nil,
},
}
Expand Down

0 comments on commit d728543

Please sign in to comment.