-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruntime_test.go
58 lines (52 loc) · 1.35 KB
/
runtime_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
package metrics
import (
"testing"
"time"
)
func TestRuntimeCollector(t *testing.T) {
if testing.Short() {
t.Skip("Skipping test because testing.Short is enabled")
}
var keys []string
latestVal := make(map[string]uint64)
gaugeFunc := func(key string, val uint64) {
keys = append(keys, key)
latestVal[key] = val
}
done := make(chan struct{})
collectorShutdown := make(chan struct{})
c := NewRuntimeCollector(gaugeFunc)
c.PauseTime = time.Second
c.Done = done
go func() {
defer close(collectorShutdown)
c.Start()
}()
time.Sleep(1500 * time.Millisecond)
close(done)
<-collectorShutdown
// we're going to check a few keys to make sure that the stats are being output
// correctly. We expect there to be three of each key because there is one
// from the initial stats, plus another one after the 1 second pause time, plus
// the final zeroing out on shutdown
expCount := 3
expKeys := []string{
"cpu.goroutines",
"mem.lookups",
"mem.gc.count",
}
for _, expKey := range expKeys {
count := 0
for _, key := range keys {
if key == expKey {
count++
}
}
if count != expCount {
t.Errorf("unexpected num stats for key(%s):\ngot: %d\nexp: %d", expKey, count, expCount)
}
if latestVal[expKey] != 0 {
t.Errorf("expected key (%s) to be zeroed out on shutdown, instead latest value is %d", expKey, latestVal[expKey])
}
}
}