| 101 | } |
| 102 | |
| 103 | func (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 | |
| 130 | func (s) TestBuffer_FreeAfterFree(t *testing.T) { |
| 131 | buf := newBuffer([]byte("abcd"), mem.NopBufferPool{}) |