-
Notifications
You must be signed in to change notification settings - Fork 2
/
stats_test.go
53 lines (48 loc) · 1.19 KB
/
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
package cache
import (
"testing"
"time"
)
func TestStatsCounter(t *testing.T) {
c := statsCounter{}
c.RecordHits(3)
c.RecordMisses(2)
c.RecordLoadSuccess(2 * time.Second)
c.RecordLoadError(1 * time.Second)
c.RecordEviction()
var st Stats
c.Snapshot(&st)
if st.HitCount != 3 {
t.Fatalf("unexpected hit count: %v", st)
}
if st.MissCount != 2 {
t.Fatalf("unexpected miss count: %v", st)
}
if st.LoadSuccessCount != 1 {
t.Fatalf("unexpected success count: %v", st)
}
if st.LoadErrorCount != 1 {
t.Fatalf("unexpected error count: %v", st)
}
if st.TotalLoadTime != 3*time.Second {
t.Fatalf("unexpected load time: %v", st)
}
if st.EvictionCount != 1 {
t.Fatalf("unexpected eviction count: %v", st)
}
if st.RequestCount() != 5 {
t.Fatalf("unexpected request count: %v", st.RequestCount())
}
if st.HitRate() != 0.6 {
t.Fatalf("unexpected hit rate: %v", st.HitRate())
}
if st.MissRate() != 0.4 {
t.Fatalf("unexpected miss rate: %v", st.MissRate())
}
if st.LoadErrorRate() != 0.5 {
t.Fatalf("unexpected error rate: %v", st.LoadErrorRate())
}
if st.AverageLoadPenalty() != (1500 * time.Millisecond) {
t.Fatalf("unexpected load penalty: %v", st.AverageLoadPenalty())
}
}