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

Method TestBuffer_NewBufferHandlesShortBuffers

mem/buffers_test.go:103–128  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

101}
102
103func (s) TestBuffer_NewBufferHandlesShortBuffers(t *testing.T) {
104 const threshold = 100
105
106 // Update the pooling threshold, since that's what's being tested.
107 internal.SetBufferPoolingThresholdForTesting.(func(int))(threshold)
108 t.Cleanup(func() {
109 internal.SetBufferPoolingThresholdForTesting.(func(int))(0)
110 })
111
112 // Make a pool with a buffer whose capacity is larger than the pooling
113 // threshold, but whose length is less than the threshold.
114 b := make([]byte, threshold/2, threshold*2)
115 pool := &singleBufferPool{
116 t: t,
117 data: &b,
118 }
119
120 // Get a Buffer, then free it. If NewBuffer decided that the Buffer
121 // shouldn't get pooled, Free will be a noop and singleBufferPool will not
122 // have been updated.
123 mem.NewBuffer(&b, pool).Free()
124
125 if pool.data != nil {
126 t.Fatalf("Buffer not returned to pool")
127 }
128}
129
130func (s) TestBuffer_FreeAfterFree(t *testing.T) {
131 buf := newBuffer([]byte("abcd"), mem.NopBufferPool{})

Callers

nothing calls this directly

Calls 3

NewBufferFunction · 0.92
FreeMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected