-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregression_test.go
More file actions
163 lines (145 loc) · 4.55 KB
/
Copy pathregression_test.go
File metadata and controls
163 lines (145 loc) · 4.55 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package testrunner
import (
"testing"
)
func TestCompareBaseline_P99Increase(t *testing.T) {
baseline := map[string]float64{"p99_write_latency_seconds": 0.005}
current := map[string]float64{"p99_write_latency_seconds": 0.006} // +20%
results := CompareBaseline(baseline, current)
if len(results) == 0 {
t.Fatal("expected results")
}
for _, r := range results {
if r.Metric == "p99_write_latency_seconds" && r.Pass {
t.Error("expected FAIL for 20% latency increase (limit 10%)")
}
}
}
func TestCompareBaseline_P99WithinLimit(t *testing.T) {
baseline := map[string]float64{"p99_write_latency_seconds": 0.005}
current := map[string]float64{"p99_write_latency_seconds": 0.0054} // +8%
results := CompareBaseline(baseline, current)
for _, r := range results {
if r.Metric == "p99_write_latency_seconds" && !r.Pass {
t.Errorf("expected PASS for 8%% increase (limit 10%%): %s", r.Reason)
}
}
}
func TestCompareBaseline_IOPSDecrease(t *testing.T) {
baseline := map[string]float64{"write_iops": 50000}
current := map[string]float64{"write_iops": 46000} // -8%
results := CompareBaseline(baseline, current)
for _, r := range results {
if r.Metric == "write_iops" && r.Pass {
t.Error("expected FAIL for 8% IOPS decrease (limit 5%)")
}
}
}
func TestCompareBaseline_IOPSWithinLimit(t *testing.T) {
baseline := map[string]float64{"write_iops": 50000}
current := map[string]float64{"write_iops": 48000} // -4%
results := CompareBaseline(baseline, current)
for _, r := range results {
if r.Metric == "write_iops" && !r.Pass {
t.Errorf("expected PASS for 4%% decrease (limit 5%%): %s", r.Reason)
}
}
}
func TestHardFail_DataMismatch(t *testing.T) {
metrics := map[string]float64{"data_mismatch_count": 1}
results := RunHardFailChecks(metrics)
for _, r := range results {
if r.Condition == "data_mismatch" && r.Pass {
t.Error("expected FAIL for data mismatch")
}
}
}
func TestHardFail_BarrierLagUnbounded(t *testing.T) {
metrics := map[string]float64{"barrier_lag_lsn_max": 1500}
results := RunHardFailChecks(metrics)
for _, r := range results {
if r.Condition == "barrier_lag_lsn_unbounded" && r.Pass {
t.Error("expected FAIL for barrier_lag_lsn=1500")
}
}
}
func TestHardFail_BarrierLagOK(t *testing.T) {
metrics := map[string]float64{"barrier_lag_lsn_max": 50}
results := RunHardFailChecks(metrics)
for _, r := range results {
if r.Condition == "barrier_lag_lsn_unbounded" && !r.Pass {
t.Error("expected PASS for barrier_lag_lsn=50")
}
}
}
func TestHardFail_BarrierErrorRate(t *testing.T) {
metrics := map[string]float64{
"barrier_requests_total": 100,
"barrier_failures_total": 10, // 10% error rate
}
results := RunHardFailChecks(metrics)
for _, r := range results {
if r.Condition == "barrier_error_rate" && r.Pass {
t.Error("expected FAIL for 10% barrier error rate")
}
}
}
func TestHardFail_HealthZero(t *testing.T) {
metrics := map[string]float64{"health_score": 0.0, "fault_active": 0}
results := RunHardFailChecks(metrics)
for _, r := range results {
if r.Condition == "health_zero_without_fault" && r.Pass {
t.Error("expected FAIL for health=0 without fault")
}
}
}
func TestHardFail_HealthZeroDuringFault_OK(t *testing.T) {
metrics := map[string]float64{"health_score": 0.0, "fault_active": 1}
results := RunHardFailChecks(metrics)
for _, r := range results {
if r.Condition == "health_zero_without_fault" && !r.Pass {
t.Error("expected PASS for health=0 during active fault")
}
}
}
func TestHardFail_WALFullStall(t *testing.T) {
metrics := map[string]float64{"wal_full_duration_seconds": 15}
results := RunHardFailChecks(metrics)
for _, r := range results {
if r.Condition == "wal_full_stall" && r.Pass {
t.Error("expected FAIL for WAL full 15s")
}
}
}
func TestHardFail_AllPass(t *testing.T) {
metrics := map[string]float64{
"health_score": 1.0,
"barrier_lag_lsn_max": 10,
}
results := RunHardFailChecks(metrics)
for _, r := range results {
if !r.Pass {
t.Errorf("expected all PASS, got FAIL for %s: %s", r.Condition, r.Detail)
}
}
}
func TestFormatRegressionReport(t *testing.T) {
report := &RegressionReport{
Results: []RegressionResult{
{Metric: "p99_write_latency_seconds", BaselineVal: 0.005, CurrentVal: 0.006, Pass: false, Reason: "change=+20%"},
},
HardFails: []HardFailResult{
{Condition: "data_mismatch", Pass: true},
},
OverallPass: false,
BaselineGitSHA: "abc123",
CurrentGitSHA: "def456",
}
s := FormatRegressionReport(report)
if s == "" {
t.Error("expected non-empty report")
}
if len(s) < 50 {
t.Errorf("report too short: %s", s)
}
}