-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculator_test.go
55 lines (43 loc) · 1.75 KB
/
calculator_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
package main
import (
"testing"
"net/http"
)
var testGetRequestLatencies = []int{
10, 20, 24, 30, 12, 27, 18, 57, 9, 14,
12, 10, 54, 33, 23, 54, 3, 4, 5, 7, 1,
10, 15, 12, 34, 21, 12, 34, 3, 4, 6, 7,
}
func TestCalculate(t *testing.T) {
calculator := NewCalculator(15)
calculator.CalculatePerTrial(testGetRequestLatencies, http.MethodGet, 1, map[int]int{})
metrics := calculator.GetMetricsResult()
if int(metrics.GetMetrics[0].Rps) != (len(testGetRequestLatencies) / durationSeconds) {
t.Fatalf("Not equals RPS. Expect = %d, Actual = %d", len(testGetRequestLatencies), int(metrics.GetMetrics[0].Rps))
}
if int(metrics.GetMetrics[0].PercentileAvg) != 18 {
t.Fatalf("Not equals avg percentile. Expect = 18, Actual = %d", int(metrics.GetMetrics[0].PercentileAvg))
}
if int(metrics.GetMetrics[0].PercentileMin) != 1 {
t.Fatalf("Not equals min percentile. Expect = 1, Actual = %d", int(metrics.GetMetrics[0].PercentileMin))
}
if int(metrics.GetMetrics[0].PercentileMax) != 57 {
t.Fatalf("Not equals max percentile. Expect = 57, Actual = %d", int(metrics.GetMetrics[0].PercentileMax))
}
if int(metrics.GetMetrics[0].Percentile95) != 54 {
t.Fatalf("Not equals 95 percentile. Expect = %d, Actual = %d", 54, int(metrics.GetMetrics[0].Percentile95))
}
if int(metrics.GetMetrics[0].Percentile99) != 57 {
t.Fatalf("Not equals 99 percentile. Expect = %d, Actual = %d", 57, int(metrics.GetMetrics[0].Percentile99))
}
if int(metrics.GetMetrics[1].Percentile95) != 0 && int(metrics.GetMetrics[1].Percentile99) != 0 {
t.Fatalf("Cap is always zero when index is not 0")
}
}
func TestPercentileN(t *testing.T) {
calculator := NewCalculator(1)
ignoreIndex := calculator.PercentileN(8, 95)
if ignoreIndex != 8 {
t.Fatalf("Failed to percentile calculator.")
}
}