Skip to content

Commit

Permalink
Merge pull request #1084 from aymanbagabas/sideband-flush
Browse files Browse the repository at this point in the history
plumbing: fix sideband demux on flush
  • Loading branch information
pjbgf committed Apr 27, 2024
2 parents 1ddd78a + 59b792b commit d6bb286
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plumbing/protocol/packp/sideband/demux.go
Expand Up @@ -114,7 +114,7 @@ func (d *Demuxer) nextPackData() ([]byte, error) {

size := len(content)
if size == 0 {
return nil, nil
return nil, io.EOF
} else if size > d.max {
return nil, ErrMaxPackedExceeded
}
Expand Down
29 changes: 27 additions & 2 deletions plumbing/protocol/packp/sideband/demux_test.go
Expand Up @@ -105,8 +105,34 @@ func (s *SidebandSuite) TestDecodeWithProgress(c *C) {
c.Assert(progress, DeepEquals, []byte{'F', 'O', 'O', '\n'})
}

func (s *SidebandSuite) TestDecodeWithUnknownChannel(c *C) {
func (s *SidebandSuite) TestDecodeFlushEOF(c *C) {
expected := []byte("abcdefghijklmnopqrstuvwxyz")

input := bytes.NewBuffer(nil)
e := pktline.NewEncoder(input)
e.Encode(PackData.WithPayload(expected[0:8]))
e.Encode(ProgressMessage.WithPayload([]byte{'F', 'O', 'O', '\n'}))
e.Encode(PackData.WithPayload(expected[8:16]))
e.Encode(PackData.WithPayload(expected[16:26]))
e.Flush()
e.Encode(PackData.WithPayload([]byte("bar\n")))

output := bytes.NewBuffer(nil)
content := bytes.NewBuffer(nil)
d := NewDemuxer(Sideband64k, input)
d.Progress = output

n, err := content.ReadFrom(d)
c.Assert(err, IsNil)
c.Assert(n, Equals, int64(26))
c.Assert(content.Bytes(), DeepEquals, expected)

progress, err := io.ReadAll(output)
c.Assert(err, IsNil)
c.Assert(progress, DeepEquals, []byte{'F', 'O', 'O', '\n'})
}

func (s *SidebandSuite) TestDecodeWithUnknownChannel(c *C) {
buf := bytes.NewBuffer(nil)
e := pktline.NewEncoder(buf)
e.Encode([]byte{'4', 'F', 'O', 'O', '\n'})
Expand Down Expand Up @@ -150,5 +176,4 @@ func (s *SidebandSuite) TestDecodeErrMaxPacked(c *C) {
n, err := io.ReadFull(d, content)
c.Assert(err, Equals, ErrMaxPackedExceeded)
c.Assert(n, Equals, 0)

}

0 comments on commit d6bb286

Please sign in to comment.