MCPcopy
hub / github.com/grpc/grpc-go / TestBuffer_CopyAndFree

Method TestBuffer_CopyAndFree

mem/buffers_test.go:163–180  ·  view source on GitHub ↗

Tests that a buffer created with Copy, which when later freed, returns the underlying byte slice to the buffer pool.

(t *testing.T)

Source from the content-addressed store, hash-verified

161// Tests that a buffer created with Copy, which when later freed, returns the underlying
162// byte slice to the buffer pool.
163func (s) TestBuffer_CopyAndFree(t *testing.T) {
164 data := []byte("abcd")
165 testPool := &singleBufferPool{
166 t: t,
167 data: &data,
168 }
169
170 buf := mem.Copy(data, testPool)
171 if got := buf.ReadOnlyData(); !bytes.Equal(got, data) {
172 t.Fatalf("Buffer contains data %s, want %s", string(got), string(data))
173 }
174
175 // Verify that the free function is invoked when all references are freed.
176 buf.Free()
177 if testPool.data != nil {
178 t.Fatalf("Buffer not freed")
179 }
180}
181
182// Tests that a buffer created with Copy, on which an additional reference is
183// acquired, which when later freed, returns the underlying byte slice to the

Callers

nothing calls this directly

Calls 5

CopyFunction · 0.92
ReadOnlyDataMethod · 0.65
EqualMethod · 0.65
FatalfMethod · 0.65
FreeMethod · 0.65

Tested by

no test coverage detected