Skip to content

Commit

Permalink
byteswith output unaffected by buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d committed Oct 27, 2020
1 parent 48fa77f commit 7ec0fb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/chunkenc/memchunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (c *MemChunk) BytesWith(b []byte) ([]byte, error) {
}
crc32Hash := newCRC32()

buf := bytes.NewBuffer(b)
buf := bytes.NewBuffer(b[:0])
offset := 0

eb := encbuf{b: make([]byte, 0, 1<<10)}
Expand Down
10 changes: 10 additions & 0 deletions pkg/chunkenc/memchunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,3 +767,13 @@ func TestMemchunkLongLine(t *testing.T) {
})
}
}

// Ensure passing a reusable []byte doesn't affect output
func TestBytesWith(t *testing.T) {
exp, err := NewMemChunk(EncNone, testBlockSize, testTargetSize).BytesWith(nil)
require.Nil(t, err)
out, err := NewMemChunk(EncNone, testBlockSize, testTargetSize).BytesWith([]byte{1, 2, 3})
require.Nil(t, err)

require.Equal(t, exp, out)
}
3 changes: 3 additions & 0 deletions pkg/ingester/checkpoint.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7ec0fb0

Please sign in to comment.