Commit ad658493 authored by Aaron Jacobs's avatar Aaron Jacobs

Add a test for OutMessage.Grow.

parent e329c0ef
......@@ -92,7 +92,10 @@ func TestOutMessageReset(t *testing.T) {
const trials = 100
for i := 0; i < trials; i++ {
fillWithGarbage(unsafe.Pointer(h), int(unsafe.Sizeof(*h)))
err := fillWithGarbage(unsafe.Pointer(h), int(unsafe.Sizeof(*h)))
if err != nil {
t.Fatalf("fillWithGarbage: %v", err)
}
om.Reset()
if h.Len != 0 {
......@@ -109,6 +112,32 @@ func TestOutMessageReset(t *testing.T) {
}
}
func TestOutMessageGrow(t *testing.T) {
var om OutMessage
// Overwrite with garbage.
err := fillWithGarbage(unsafe.Pointer(&om), int(unsafe.Sizeof(om)))
if err != nil {
t.Fatalf("fillWithGarbage: %v", err)
}
// Zero the header.
om.Reset()
// Grow to the max size. This should zero the message.
if p := om.Grow(MaxReadSize); p == nil {
t.Fatal("Grow returned nil")
}
// Check that everything has been zeroed.
b := om.Bytes()
for i, x := range b {
if x != 0 {
t.Fatalf("non-zero byte 0x%02x at offset %d", x, i)
}
}
}
func BenchmarkOutMessageReset(b *testing.B) {
// A single buffer, which should fit in some level of CPU cache.
b.Run("Single buffer", func(b *testing.B) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment