Ensure maxSize > 0
This commit is contained in:
@@ -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{},
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user