mirror of
https://github.com/smallnest/rpcx.git
synced 2025-09-26 20:21:14 +08:00
fix: fix pool unit test
This commit is contained in:
@@ -7,15 +7,21 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPool(t *testing.T) {
|
||||
// THE Magic Number
|
||||
magicNumber := 42
|
||||
|
||||
intType := reflect.TypeOf(magicNumber)
|
||||
// init int pool
|
||||
reflectTypePools.Init(intType)
|
||||
|
||||
reflectTypePools.Put(intType, magicNumber)
|
||||
// Get() will remove element from pool
|
||||
assert.Equal(t, magicNumber, reflectTypePools.Get(intType).(int))
|
||||
type Elem struct {
|
||||
// magicNumber the Magic Number
|
||||
magicNumber int
|
||||
}
|
||||
|
||||
func (e Elem) Reset() {
|
||||
|
||||
}
|
||||
|
||||
func TestPool(t *testing.T) {
|
||||
elem := Elem{42}
|
||||
elemType := reflect.TypeOf(elem)
|
||||
// init Elem pool
|
||||
reflectTypePools.Init(elemType)
|
||||
reflectTypePools.Put(elemType, elem)
|
||||
// Get() will remove element from pool
|
||||
assert.Equal(t, elem.magicNumber, reflectTypePools.Get(elemType).(Elem).magicNumber)
|
||||
}
|
||||
|
Reference in New Issue
Block a user