Skip to content

Commit

Permalink
util/pool: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Feb 21, 2024
1 parent c0bce56 commit 1a7a42a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ func NewResetPool[T Resetable](newFn func() T) *ResetPool[T] {

func (p *ResetPool[T]) Put(v T) {
v.Reset()
p.p.Put(v)
p.Pool.Put(v)
}
30 changes: 30 additions & 0 deletions util/pool/pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package pool_test

import (
"testing"

"github.com/R-a-dio/valkyrie/util/pool"
"github.com/stretchr/testify/assert"
)

type testResetable struct {
called bool
}

func (tr *testResetable) Reset() {
tr.called = true
}

func TestResetPool(t *testing.T) {
var called bool
p := pool.NewResetPool(func() *testResetable {
called = true
return &testResetable{}
})

x := p.Get()
assert.True(t, called)

p.Put(x)
assert.True(t, x.called)
}

0 comments on commit 1a7a42a

Please sign in to comment.