-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
metric_test.go
51 lines (47 loc) · 976 Bytes
/
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
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.QueuedMessage) error {
switch string(m.Bytes()) {
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, 4, q.SubmittedTasks())
assert.Equal(t, 2, q.SuccessTasks())
assert.Equal(t, 2, q.FailureTasks())
q.Release()
}