-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsink_test.go
50 lines (44 loc) · 1.21 KB
/
sink_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
package stats
import (
"context"
"fmt"
"testing"
"time"
)
type dummySink struct {
counterCount int
timerCount int
}
func (ds *dummySink) WriteCounters(ctx context.Context, counters ...*Counter) error {
ds.counterCount = ds.counterCount + len(counters)
return nil
}
func (ds *dummySink) WriteTimers(ctx context.Context, timers ...*Timer) error {
ds.timerCount = ds.timerCount + len(timers)
return nil
}
func TestDaemon(t *testing.T) {
// se
parentContext, cancelF := context.WithCancel(context.Background())
rs := newRequestStats()
sink := &dummySink{}
requestContext := initRequestContext(parentContext, rs, sink)
var i int
for i = 0; i < 10; i++ {
StartTimer(requestContext, "test_timer")
Increment(requestContext, fmt.Sprintf("test_counter_%d", i))
FinishTimer(requestContext, "test_timer")
}
cancelF()
// NB: Following is to let the daemon finish, but baking in an
// explicit notification channel would be better
select {
case <-time.After(100 * time.Millisecond):
}
if sink.counterCount != i {
t.Errorf("Dropped counters: expected %d but only sent %d", i, sink.counterCount)
}
if sink.timerCount != i {
t.Errorf("Dropped timers: expected %d but only sent %d", i, sink.timerCount)
}
}