(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func (s) TestBufferPool_Clears(t *testing.T) { |
| 38 | poolConfigs := []struct { |
| 39 | name string |
| 40 | factory func() (*mem.BinaryTieredBufferPool, error) |
| 41 | wantCleared bool |
| 42 | bufferSize int |
| 43 | }{ |
| 44 | { |
| 45 | name: "regular_sized", |
| 46 | factory: func() (*mem.BinaryTieredBufferPool, error) { |
| 47 | return mem.NewBinaryTieredBufferPool(3) // 8 bytes |
| 48 | }, |
| 49 | bufferSize: 8, |
| 50 | wantCleared: true, |
| 51 | }, |
| 52 | { |
| 53 | name: "regular_fallback", |
| 54 | factory: func() (*mem.BinaryTieredBufferPool, error) { |
| 55 | return mem.NewBinaryTieredBufferPool(3) |
| 56 | }, |
| 57 | bufferSize: 10, |
| 58 | wantCleared: true, |
| 59 | }, |
| 60 | { |
| 61 | name: "dirty_sized", |
| 62 | factory: func() (*mem.BinaryTieredBufferPool, error) { |
| 63 | return mem.NewDirtyBinaryTieredBufferPool(3) |
| 64 | }, |
| 65 | bufferSize: 8, |
| 66 | wantCleared: false, |
| 67 | }, |
| 68 | { |
| 69 | name: "dirty_fallback", |
| 70 | factory: func() (*mem.BinaryTieredBufferPool, error) { |
| 71 | return mem.NewDirtyBinaryTieredBufferPool(3) |
| 72 | }, |
| 73 | bufferSize: 10, |
| 74 | wantCleared: false, |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | for _, tc := range poolConfigs { |
| 79 | t.Run(tc.name, func(t *testing.T) { |
| 80 | pool, err := tc.factory() |
| 81 | if err != nil { |
| 82 | t.Fatalf("Failed to create pool: %v", err) |
| 83 | } |
| 84 | |
| 85 | for { |
| 86 | buf1 := pool.Get(tc.bufferSize) |
| 87 | // Mark the buffer with data. |
| 88 | for i := range *buf1 { |
| 89 | (*buf1)[i] = 0xAA |
| 90 | } |
| 91 | pool.Put(buf1) |
| 92 | |
| 93 | buf2 := pool.Get(tc.bufferSize) |
| 94 | // Check if we got the same underlying array. |
nothing calls this directly
no test coverage detected