forked from facebookarchive/flashback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_analyser_test.go
95 lines (80 loc) · 2.17 KB
/
stats_analyser_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package flashback
import (
"testing"
"time"
. "gopkg.in/check.v1"
)
// Hook up gocheck into the "go test" runner.
func TestStatsAnalyzer(t *testing.T) {
TestingT(t)
}
type TestStatsAnalyzerSuite struct{}
var _ = Suite(&TestStatsAnalyzerSuite{})
func (s *TestStatsAnalyzerSuite) TestBasics(c *C) {
opsExecuted := int64(0)
latencyChan := make(chan Latency)
analyser := NewStatsAnalyzer(
[]*StatsCollector{}, &opsExecuted, latencyChan, 1000,
)
for _, latencyList := range analyser.latencies {
c.Assert(latencyList, HasLen, 0)
}
for i := 0; i < 10; i += 1 {
for _, opType := range AllOpTypes {
latencyChan <- Latency{opType, time.Duration(i)}
}
}
// Need to sleep for a while to make sure the channel got everything
time.Sleep(10)
for _, latencyList := range analyser.latencies {
c.Assert(latencyList, HasLen, 10)
}
}
func (s *TestStatsAnalyzerSuite) TestLatencies(c *C) {
opsExecuted := int64(0)
latencyChan := make(chan Latency)
analyser := NewStatsAnalyzer(
[]*StatsCollector{}, &opsExecuted, latencyChan, 1000,
)
start := 1000
for _, opType := range AllOpTypes {
for i := 100; i >= 0; i-- {
latencyChan <- Latency{opType, time.Duration(start + i)}
}
start += 2000
}
time.Sleep(10)
status := analyser.GetStatus()
// Check results
start = 1000
for _, opType := range AllOpTypes {
sinceLast := status.SinceLastLatencies[opType]
allTime := status.AllTimeLatencies[opType]
for i, perc := range latencyPercentiles {
c.Assert(sinceLast[i], Equals, int64(perc+start))
c.Assert(allTime[i], Equals, int64(perc+start))
}
start += 2000
}
// -- second round
start = 2000
for _, opType := range AllOpTypes {
for i := 100; i >= 0; i-- {
latencyChan <- Latency{opType, time.Duration(start + i)}
}
start += 2000
}
time.Sleep(10)
status = analyser.GetStatus()
start = 2000
for _, opType := range AllOpTypes {
sinceLast := status.SinceLastLatencies[opType]
allTime := status.AllTimeLatencies[opType]
for i, perc := range latencyPercentiles {
c.Assert(sinceLast[i], Equals, int64(perc+start))
}
c.Assert(allTime[len(allTime)-1], Equals, int64(start+100))
c.Assert(allTime[0], Equals, int64(start-1000+100))
start += 2000
}
}