-
Notifications
You must be signed in to change notification settings - Fork 8
/
options_test.go
65 lines (50 loc) · 1.34 KB
/
options_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
64
65
package goroutines
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type optionsSuite struct {
suite.Suite
}
func (s *optionsSuite) SetupSuite() {}
func (s *optionsSuite) TearDownSuite() {}
func (s *optionsSuite) SetupTest() {}
func (s *optionsSuite) TearDownTest() {}
func TestOptionsSuite(t *testing.T) {
suite.Run(t, new(optionsSuite))
}
func (s *optionsSuite) TestInvalidTaskQueueLength() {
defer func() {
r := recover()
s.Require().NotNil(r)
s.Require().Equal(errors.New("the length of task queue must be greater than or equal to zero"), r)
}()
NewPool(10, WithTaskQueueLength(-1))
}
func (s *optionsSuite) TestInvalidPreAllocWorkers() {
defer func() {
r := recover()
s.Require().NotNil(r)
s.Require().Equal(errors.New("the pre-allocated number of workers must be greater than or equal to zero"), r)
}()
NewPool(10, WithPreAllocWorkers(-1))
}
func (s *optionsSuite) TestInvalidWorkerAdjustPeriod() {
defer func() {
r := recover()
s.Require().NotNil(r)
s.Require().Equal(errors.New("the period of adjusting workers must be greater than zero"), r)
}()
NewPool(10, WithWorkerAdjustPeriod(time.Duration(0)))
}
func (s *optionsSuite) TestValidOptions() {
p := NewPool(
10,
WithTaskQueueLength(0),
WithPreAllocWorkers(0),
WithWorkerAdjustPeriod(time.Duration(time.Second)),
)
p.Release()
}