2
0

Ensure maxSize > 0

This commit is contained in:
Jack Christensen
2019-04-13 18:43:25 -05:00
parent 0395a39c2d
commit e4ced69a3a
2 changed files with 11 additions and 1 deletions
+5 -1
View File
@@ -94,8 +94,12 @@ type Pool struct {
closed bool
}
// NewPool creates a new pool.
// NewPool creates a new pool. Panics if maxSize is less than 1.
func NewPool(constructor Constructor, destructor Destructor, maxSize int32) *Pool {
if maxSize < 1 {
panic("maxSize is less than 1")
}
return &Pool{
cond: sync.NewCond(new(sync.Mutex)),
destructWG: &sync.WaitGroup{},
+6
View File
@@ -72,6 +72,12 @@ func waitForRead(ch chan int) bool {
}
}
func TestNewPoolRequiresMaxSizeGreaterThan0(t *testing.T) {
constructor, _ := createConstructor()
assert.Panics(t, func() { puddle.NewPool(constructor, stubDestructor, -1) })
assert.Panics(t, func() { puddle.NewPool(constructor, stubDestructor, 0) })
}
func TestPoolAcquireCreatesResourceWhenNoneIdle(t *testing.T) {
constructor, _ := createConstructor()
pool := puddle.NewPool(constructor, stubDestructor, 10)