-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathjson_polling_sink_test.go
More file actions
36 lines (27 loc) · 1014 Bytes
/
json_polling_sink_test.go
File metadata and controls
36 lines (27 loc) · 1014 Bytes
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
package health
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestJsonPollingSink(t *testing.T) {
setNowMock("2011-09-09T23:36:13Z")
defer resetNowMock()
sink := NewJsonPollingSink(time.Minute, time.Minute*5)
sink.EmitEvent("myjob", "myevent", nil)
sink.EmitEventErr("myjob", "myevent", errors.New("myerr"), nil)
sink.EmitTiming("myjob", "myevent", 100, nil)
sink.EmitGauge("myjob", "myevent", 3.14, nil)
sink.EmitComplete("myjob", Success, 9, nil)
time.Sleep(10 * time.Millisecond) // we need to make sure we process the above metrics before we get the metrics.
intervals := sink.GetMetrics()
sink.ShutdownServer()
assert.Equal(t, 1, len(intervals))
intAgg := intervals[0]
assert.EqualValues(t, 1, intAgg.Events["myevent"])
assert.EqualValues(t, 3.14, intAgg.Gauges["myevent"])
assert.EqualValues(t, 1, intAgg.EventErrs["myevent"].Count)
assert.EqualValues(t, 1, intAgg.Timers["myevent"].Count)
assert.EqualValues(t, 1, intAgg.Jobs["myjob"].Count)
}