-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers_test.go
42 lines (34 loc) · 1.19 KB
/
helpers_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
package metrics
import (
"testing"
"time"
"github.com/rcrowley/go-metrics"
"github.com/stretchr/testify/assert"
)
func TestHelpers(t *testing.T) {
_ = Setup(
"graphite",
"localhost",
2003,
"",
time.Hour, // don't flush metrics until Close call
)
go Scheduler(time.Hour, MeasureRuntime, []string{"uptime"}, time.Time{})
GoRuntimeStats([]string{"r"})
// wait for stats to be dumped
Close(true)
// check GoRuntimeStats
assert.Nil(t, emm.registry.Get("runtime.random_metric"), "random metric is not present")
assert.NotNil(t, emm.registry.Get("r.runtime.num_goroutines"))
assert.NotNil(t, emm.registry.Get("r.runtime.heap_alloc"))
assert.NotNil(t, emm.registry.Get("r.runtime.sys"))
assert.NotNil(t, emm.registry.Get("r.runtime.pause_total_ns"))
assert.NotNil(t, emm.registry.Get("r.runtime.num_gc"))
assert.NotNil(t, emm.registry.Get("r.runtime.heap_released"))
assert.NotNil(t, emm.registry.Get("r.runtime.heap_objects"))
// check Scheduler and MeasureRuntime
// Scheduler problem cases are not tested
assert.Equal(t, (time.Now().Sub(time.Time{}) / time.Millisecond).Nanoseconds(), emm.registry.Get("uptime").(metrics.Gauge).Value())
// cleanup
emm.registry.UnregisterAll()
}