forked from segmentio/stats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler_test.go
49 lines (38 loc) · 974 Bytes
/
handler_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
package stats_test
import (
"testing"
"time"
"github.com/segmentio/stats"
"github.com/segmentio/stats/statstest"
)
func TestMultiHandler(t *testing.T) {
t.Run("calling HandleMeasures on a multi-handler dispatches to each handler", func(t *testing.T) {
n := 0
f := stats.HandlerFunc(func(time time.Time, measures ...stats.Measure) { n++ })
m := stats.MultiHandler(f, f, f)
m.HandleMeasures(time.Now())
if n != 3 {
t.Error("bad number of calls to HandleMeasures:", n)
}
})
t.Run("calling Flush on a multi-handler flushes each handler", func(t *testing.T) {
h1 := &statstest.Handler{}
h2 := &statstest.Handler{}
m := stats.MultiHandler(h1, h2)
flush(m)
flush(m)
n1 := h1.FlushCalls()
n2 := h2.FlushCalls()
if n1 != 2 {
t.Error("bad number of calls to Flush:", n1)
}
if n2 != 2 {
t.Error("bad number of calls to Flush:", n2)
}
})
}
func flush(h stats.Handler) {
if f, ok := h.(stats.Flusher); ok {
f.Flush()
}
}