-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclass_test.go
71 lines (64 loc) · 1.82 KB
/
class_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
// Copyright 2019 Daniel Nichter
package slowlog_test
import (
"testing"
"github.com/go-mysql/slowlog"
"github.com/go-test/deep"
)
func TestAggregateClass(t *testing.T) {
c1 := &slowlog.Class{
Id: "111",
Fingerprint: "select *",
TotalQueries: 5,
UniqueQueries: 1,
Metrics: slowlog.Metrics{
TimeMetrics: map[string]*slowlog.TimeStats{
"Query_time": {Sum: 1.123, Min: 0.100, Avg: 0.2, Med: 0.155, P95: 0.101, Max: 3.222},
},
NumberMetrics: map[string]*slowlog.NumberStats{
"Rows_sent": {Sum: 90, Min: 4, Avg: 18, Med: 7, P95: 8, Max: 10},
},
BoolMetrics: map[string]*slowlog.BoolStats{
"Full_scan": {Sum: 10},
},
},
}
c2 := &slowlog.Class{
Id: "222",
Fingerprint: "insert t",
TotalQueries: 4,
UniqueQueries: 1,
Metrics: slowlog.Metrics{
TimeMetrics: map[string]*slowlog.TimeStats{
"Query_time": {Sum: 1.123, Min: 0.111, Avg: 0.2, Med: 5.555, P95: 9.999, Max: 5.222},
},
NumberMetrics: map[string]*slowlog.NumberStats{
"Rows_sent": {Sum: 100, Min: 0, Avg: 25, Med: 7, P95: 8, Max: 11},
},
BoolMetrics: map[string]*slowlog.BoolStats{
"Full_scan": {Sum: 10},
},
},
}
expect := &slowlog.Class{
Id: "anId",
Fingerprint: "aFingerprint",
TotalQueries: 9,
UniqueQueries: 2,
Metrics: slowlog.Metrics{
TimeMetrics: map[string]*slowlog.TimeStats{
"Query_time": {Sum: 2.246, Min: 0.100, Avg: 0.2495555, Med: 0.155, P95: 0.101, Max: 5.222},
},
NumberMetrics: map[string]*slowlog.NumberStats{
"Rows_sent": {Sum: 190, Min: 0, Avg: 21, Med: 7, P95: 8, Max: 11},
},
BoolMetrics: map[string]*slowlog.BoolStats{
"Full_scan": {Sum: 20},
},
},
}
got := slowlog.NewAggregateClass("anId", "aFingerprint", []*slowlog.Class{c1, c2})
if diff := deep.Equal(got, expect); diff != nil {
t.Error(diff)
}
}