-
Notifications
You must be signed in to change notification settings - Fork 5
/
pool_test.go
63 lines (51 loc) · 1.03 KB
/
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
60
61
62
63
package don_test
import (
"reflect"
"testing"
"github.com/abemedia/go-don"
)
func TestRequestPool(t *testing.T) {
type item struct {
String string
Pointer *string
}
t.Run("Nil", func(t *testing.T) {
var zero any
pool := don.NewRequestPool(zero)
pool.Put(pool.Get())
if !reflect.DeepEqual(&zero, pool.Get()) {
t.Fatal("should be zero value")
}
})
t.Run("Struct", func(t *testing.T) {
zero := item{}
pool := don.NewRequestPool(zero)
for i := 0; i < 100; i++ {
v := pool.Get()
v.String = "test"
v.Pointer = &v.String
pool.Put(v)
}
for i := 0; i < 100; i++ {
if !reflect.DeepEqual(&zero, pool.Get()) {
t.Fatal("should be zero value")
}
}
})
t.Run("Pointer", func(t *testing.T) {
zero := &item{}
pool := don.NewRequestPool(zero)
for i := 0; i < 100; i++ {
p := pool.Get()
v := *p
v.String = "test"
v.Pointer = &v.String
pool.Put(p)
}
for i := 0; i < 100; i++ {
if !reflect.DeepEqual(&zero, pool.Get()) {
t.Fatal("should be zero value")
}
}
})
}