-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathmetric_test.go
52 lines (48 loc) · 1.02 KB
/
metric_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
package queue
import (
"context"
"errors"
"testing"
"time"
"github.com/golang-queue/queue/core"
"github.com/stretchr/testify/assert"
)
func TestMetricData(t *testing.T) {
w := NewRing(
WithFn(func(ctx context.Context, m core.TaskMessage) error {
switch string(m.Payload()) {
case "foo1":
panic("missing something")
case "foo2":
return errors.New("missing something")
case "foo3":
return nil
}
return nil
}),
)
q, err := NewQueue(
WithWorker(w),
WithWorkerCount(4),
)
assert.NoError(t, err)
assert.NoError(t, q.Queue(mockMessage{
message: "foo1",
}))
assert.NoError(t, q.Queue(mockMessage{
message: "foo2",
}))
assert.NoError(t, q.Queue(mockMessage{
message: "foo3",
}))
assert.NoError(t, q.Queue(mockMessage{
message: "foo4",
}))
q.Start()
time.Sleep(50 * time.Millisecond)
assert.Equal(t, uint64(4), q.SubmittedTasks())
assert.Equal(t, uint64(2), q.SuccessTasks())
assert.Equal(t, uint64(2), q.FailureTasks())
assert.Equal(t, uint64(4), q.CompletedTasks())
q.Release()
}