-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmonitor_test.go
68 lines (48 loc) · 1.59 KB
/
monitor_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
package streams_test
import (
"testing"
"time"
"github.com/msales/streams/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
func TestNewMonitor(t *testing.T) {
mon := streams.NewMonitor(new(MockStats), time.Second)
defer mon.Close()
assert.Implements(t, (*streams.Monitor)(nil), mon)
}
func TestMonitor_Processed(t *testing.T) {
stat := new(MockStats)
stat.On("Inc", "node.throughput", int64(1), mock.Anything)
stat.On("Gauge", "node.back-pressure", float64(50), mock.Anything)
stat.On("Timing", "node.latency", time.Second, mock.Anything)
stat.On("Gauge", "monitor.back-pressure", mock.Anything, mock.Anything)
mon := streams.NewMonitor(stat, time.Microsecond)
mon.Processed("test", time.Second, 50)
time.Sleep(3 * time.Microsecond)
_ = mon.Close()
stat.AssertExpectations(t)
}
func TestMonitor_Committed(t *testing.T) {
stat := new(MockStats)
stat.On("Inc", "commit.commits", int64(1), mock.Anything)
stat.On("Timing", "commit.latency", time.Second, mock.Anything)
stat.On("Gauge", "monitor.back-pressure", mock.Anything, mock.Anything)
mon := streams.NewMonitor(stat, time.Microsecond)
mon.Committed(time.Second)
time.Sleep(3 * time.Microsecond)
_ = mon.Close()
stat.AssertExpectations(t)
}
type MockStats struct {
mock.Mock
}
func (s *MockStats) Gauge(name string, value float64, tags ...interface{}) {
s.Called(name, value, tags)
}
func (s *MockStats) Inc(name string, value int64, tags ...interface{}) {
s.Called(name, value, tags)
}
func (s *MockStats) Timing(name string, value time.Duration, tags ...interface{}) {
s.Called(name, value, tags)
}