-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpool_test.go
64 lines (43 loc) · 1.39 KB
/
pool_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
package gohive
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
type testRunnable struct{}
func (t testRunnable) Run() {
for {
time.Sleep(time.Millisecond * 100)
}
}
var runnableObject = testRunnable{}
func TestPool_CloseShouldReturnErrorIfAlreadyClosed(t *testing.T) {
testPool := NewFixedPool(5)
_ = testPool.Close()
actualError := testPool.Close()
assert.NotNil(t, actualError, "error should be not nil")
}
func TestPool_CloseShouldReturnNilIfPoolIsOpen(t *testing.T) {
testPool := NewFixedPool(5)
actualError := testPool.Close()
assert.Nil(t, actualError, "error should be nil")
}
func TestPool_IsPoolClosedShouldReturnTrueOrFalseIfThePoolIsClosed(t *testing.T) {
testPool := NewFixedPool(5)
closed := testPool.IsPoolClosed()
assert.Falsef(t, closed, "pool should not be closed")
_ = testPool.Close()
closed = testPool.IsPoolClosed()
assert.True(t, closed, "pool should be closed")
}
func TestPool_SubmitShouldReturnErrorIfRunnableIsPassedAsNil(t *testing.T) {
testPool := NewFixedPool(5)
actualError := testPool.Submit(nil)
assert.NotNil(t, actualError, "Submit should return error if runnable is nil")
}
func TestPool_SubmitShouldReturnErrorIfPoolIsClosed(t *testing.T) {
testPool := NewFixedPool(5)
_ = testPool.Close()
actualError := testPool.Submit(runnableObject)
assert.NotNil(t, actualError, "Submit should return error if runnable is nil")
}