-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch_stats_test.go
77 lines (63 loc) · 1.72 KB
/
search_stats_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package trc_test
import (
"context"
"math/rand"
"testing"
"github.com/peterbourgon/trc"
)
func TestSearchStatsMerge(t *testing.T) {
t.Parallel()
seed := int64(12345)
rng := rand.New(rand.NewSource(seed))
ctx := context.Background()
categories := []string{"foo", "bar", "baz", "quux"}
sourceCount := 5
sources := make([]*trc.Collector, sourceCount)
for i := range sources {
sources[i] = trc.NewDefaultCollector()
}
traceCount := 1024
for i := 0; i < traceCount; i++ {
src := sources[rng.Intn(len(sources))]
cat := categories[rng.Intn(len(categories))]
_, tr := src.NewTrace(ctx, cat)
for i := 0; i < 1+rng.Intn(10); i++ {
tr.Tracef("event %d", i+1)
}
tr.Finish()
}
responses := make([]*trc.SearchResponse, len(sources))
for i := range sources {
res, err := sources[i].Search(ctx, &trc.SearchRequest{})
AssertNoError(t, err)
responses[i] = res
}
var merged trc.SearchStats
for _, res := range responses {
merged.Merge(res.Stats)
}
overall := merged.Overall()
AssertEqual(t, 0, overall.ActiveCount)
AssertEqual(t, 0, overall.ErroredCount)
AssertEqual(t, len(trc.DefaultBucketing), len(overall.BucketCounts))
AssertEqual(t, traceCount, overall.TotalCount())
}
func TestSearchStatsIsZero(t *testing.T) {
t.Parallel()
t.Run("zero value", func(t *testing.T) {
var ss trc.SearchStats
AssertEqual(t, true, ss.IsZero())
})
t.Run("only categories", func(t *testing.T) {
var ss trc.SearchStats
ss.Categories = map[string]*trc.CategoryStats{
"foo": trc.NewCategoryStats("foo", trc.DefaultBucketing),
}
AssertEqual(t, true, ss.IsZero())
})
t.Run("only bucketing", func(t *testing.T) {
var ss trc.SearchStats
ss.Bucketing = trc.DefaultBucketing
AssertEqual(t, false, ss.IsZero())
})
}