-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbuffer_pool_test.go
59 lines (46 loc) · 961 Bytes
/
buffer_pool_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package secureio
import (
"testing"
"github.com/stretchr/testify/assert"
)
var testBufferPool = newBufferPool(64)
func TestBuffer_Read(t *testing.T) {
buf := testBufferPool.AcquireBuffer()
defer buf.Release()
buf.Grow(2)
buf.Bytes[0] = 1
buf.Bytes[1] = 2
b := make([]byte, 1)
n, err := buf.Read(b)
assert.NoError(t, err)
assert.Equal(t, 1, n)
assert.Equal(t, byte(1), b[0])
n, err = buf.Read(b)
assert.NoError(t, err)
assert.Equal(t, 1, n)
assert.Equal(t, byte(2), b[0])
}
func TestBuffer_negative(t *testing.T) {
pool := newBufferPool(64)
buf := pool.AcquireBuffer()
buf.Release()
func() {
defer func() {
assert.NotNil(t, recover())
}()
buf.isBusy = true
pool.AcquireBuffer()
}()
buf.isBusy = false
buf = pool.AcquireBuffer()
buf.Release()
assert.False(t, buf.incRefCount())
buf = pool.AcquireBuffer()
func() {
defer func() {
assert.NotNil(t, recover())
}()
buf.isBusy = false
buf.Release()
}()
}