-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
46 lines (42 loc) · 921 Bytes
/
client_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
package ninjato
import (
"testing"
"github.com/ClickHouse-Ninja/ninjato/src/point"
"github.com/stretchr/testify/assert"
)
func TestClientPush(t *testing.T) {
client := client{
backlog: make(chan *Point, 10),
}
for i := 0; i < 10; i++ {
if err := client.Push(&Point{}); !assert.NoError(t, err) {
return
}
}
if err := client.Push(&Point{}); assert.Error(t, err) {
assert.Equal(t, ErrBacklogIsFull, err)
}
<-client.backlog
{
assert.NoError(t, client.Push(&Point{}))
}
}
func BenchmarkClientPush(b *testing.B) {
client := client{
backlog: make(chan *Point, BacklogSize),
}
go func() {
for {
<-client.backlog
}
}()
b.ResetTimer()
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
client.Push(point.New("counter", 42).
WithTags(point.Tags{"country": "RU", "datacenter": "US"}).
WithFields(point.Fields{"cpu": 1, "memory": 2, "exec": 42}))
}
})
}