-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool_test.go
61 lines (51 loc) · 1.42 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
package komi
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPoolCreationClosing(t *testing.T) {
simplePool := NewWithSettings(WorkSimple(squareSimple), &Settings{
Laborers: 10,
Debug: true,
Name: "Simple Pool",
})
assert.NotNil(t, simplePool, "simple pool")
simplePool.Close()
assert.Equal(t, true, simplePool.closed, "closed flag")
assert.NotEmpty(t, simplePool.closedSignal, "closed signal channel")
simplePoolWithErrors := NewWithSettings(WorkSimpleWithErrors(squareSimpleWithErrors), &Settings{
Debug: true,
Name: "Simple Pool With Errors",
})
assert.NotNil(t, simplePoolWithErrors, "simple pool with errors")
defer simplePoolWithErrors.Close()
regularPool := New(Work(squareRegular))
regularPool.Debug()
assert.NotNil(t, regularPool, "regular pool")
defer regularPool.Close()
regularPoolWithErrors := NewWithSettings(WorkWithErrors(squarReguralWithErrors), &Settings{
Debug: true,
Name: "Regular Pool With Errors",
})
assert.NotNil(t, regularPoolWithErrors, "regular pool with errors")
defer regularPoolWithErrors.Close()
}
func squareSimple(v int) {
v *= v
}
func squareSimpleWithErrors(v int) error {
if v <= 0 {
return errors.New("only positives allowed")
}
return nil
}
func squareRegular(v int) int {
return v * v
}
func squarReguralWithErrors(v int) (int, error) {
if v <= 0 {
return -1, errors.New("only positives allowed")
}
return v * v, nil
}