-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemsampler_test.go
71 lines (60 loc) · 1.26 KB
/
memsampler_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
package statsdig_test
import (
"sync"
"testing"
"time"
"github.com/NeowayLabs/statsdig"
)
func TestMemSampler(t *testing.T) {
count := 100
var wg sync.WaitGroup
s := statsdig.NewMemSampler()
tags := []statsdig.Tag{
statsdig.Tag{
Name: "mem",
Value: "1",
},
}
wg.Add(count)
expectedTime := time.Duration(1000 * time.Millisecond)
for i := 0; i < count; i++ {
go func() {
s.Count("count")
s.Count("count", tags...)
s.Gauge("gauge", 666)
s.Gauge("gauge", 777, tags...)
s.Time("time", expectedTime)
s.Time("time", expectedTime, tags...)
wg.Done()
}()
}
wg.Wait()
checkMetric := func(name string, counter func() int) {
if counter() != count {
t.Fatalf(
"%s: expected %d but got %d",
name,
counter(),
count,
)
}
}
checkMetric("count", func() int {
return s.GetCount("count")
})
checkMetric("countWithTags", func() int {
return s.GetCount("count", tags...)
})
checkMetric("gauge", func() int {
return s.GetGauge("gauge", 666)
})
checkMetric("gaugeWithTags", func() int {
return s.GetGauge("gauge", 777, tags...)
})
checkMetric("time", func() int {
return s.GetTime("time", expectedTime)
})
checkMetric("timeWithTags", func() int {
return s.GetTime("time", expectedTime, tags...)
})
}