-
Notifications
You must be signed in to change notification settings - Fork 3
/
executor_test.go
98 lines (72 loc) · 1.45 KB
/
executor_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package executor
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestValidateConfig(t *testing.T) {
assert := assert.New(t)
executor, err := New(Config{})
assert.NotNil(err)
assert.Nil(executor)
}
func TestPublishJobSuccess(t *testing.T) {
var (
value int
as *assert.Assertions
err error
)
as = assert.New(t)
executor, err := New(DefaultConfig())
as.Nil(err)
value = 1
err = executor.Publish(func(input int) {
as.Equal(value, input)
}, value)
as.Nil(err)
executor.Wait()
}
func TestPublishJobFail(t *testing.T) {
var (
as *assert.Assertions
err error
)
as = assert.New(t)
executor, err := New(DefaultConfig())
as.Nil(err)
err = executor.Publish(func(input int) {
as.Equal(1, input)
})
as.NotNil(err)
as.Equal(err.Error(), "Call with too few input arguments")
executor.Wait()
err = executor.Publish(func(input int) {
as.Equal(1, input)
}, 1, 1)
as.NotNil(err)
as.Equal(err.Error(), "Call with too many input arguments")
executor.Wait()
}
func TestRateLimiter(t *testing.T) {
var (
as *assert.Assertions
err error
)
as = assert.New(t)
executor, err := New(Config{
ReqPerSeconds: 2,
NumWorkers: 2,
QueueSize: 10,
})
as.Nil(err)
startTime := time.Now().Unix()
for i := 0; i < 8; i++ {
err = executor.Publish(func(input int) {
as.Equal(1, input)
}, 1)
as.Nil(err)
}
executor.Close()
endTime := time.Now().Unix()
as.InDelta(endTime-startTime, 4, 1)
}