mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-03-30 21:45:40 +00:00
fix: #199 — resolve 5 Go test failures (golden fixtures, +Inf, chan marshal)
1. Update golden shapes.json goRuntime keys to match new struct fields
(goroutines, heapAllocMB, heapSysMB, etc. replacing heapMB, sysMB, etc.)
2. Fix analytics_hash_sizes hourly element shape — use explicit keys instead
of dynamicKeys to avoid flaky validation when map iteration picks 'hour'
string value against number valueShape
3. Update TestPerfEndpoint to check new goRuntime field names
4. Guard +Inf in handlePerf: use safeAvg() instead of raw division that
produces infinity when endpoint count is 0
5. Fix TestBroadcastMarshalError: use func(){} in map instead of chan int
to avoid channel-related marshal errors in test output
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -425,7 +425,7 @@ func (s *Server) handlePerf(w http.ResponseWriter, r *http.Request) {
|
||||
sorted := sortedCopy(ep.Recent)
|
||||
d := &EndpointStatsResp{
|
||||
Count: ep.Count,
|
||||
AvgMs: round(ep.TotalMs/float64(ep.Count), 1),
|
||||
AvgMs: safeAvg(ep.TotalMs, float64(ep.Count)),
|
||||
P50Ms: round(percentile(sorted, 0.5), 1),
|
||||
P95Ms: round(percentile(sorted, 0.95), 1),
|
||||
MaxMs: round(ep.MaxMs, 1),
|
||||
|
||||
@@ -397,7 +397,7 @@ func TestPerfEndpoint(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatal("expected goRuntime object in perf response")
|
||||
}
|
||||
for _, field := range []string{"heapMB", "sysMB", "numGoroutine", "numGC", "gcPauseMs"} {
|
||||
for _, field := range []string{"goroutines", "numGC", "pauseTotalMs", "lastPauseMs", "heapAllocMB", "heapSysMB", "heapInuseMB", "heapIdleMB", "numCPU"} {
|
||||
if _, ok := goRuntime[field]; !ok {
|
||||
t.Errorf("expected %s in goRuntime", field)
|
||||
}
|
||||
|
||||
43
cmd/server/testdata/golden/shapes.json
vendored
43
cmd/server/testdata/golden/shapes.json
vendored
@@ -168,13 +168,18 @@
|
||||
"type": "array",
|
||||
"elementShape": {
|
||||
"type": "object",
|
||||
"dynamicKeys": true,
|
||||
"valueShape": {
|
||||
"type": "number"
|
||||
},
|
||||
"requiredKeys": {
|
||||
"keys": {
|
||||
"hour": {
|
||||
"type": "string"
|
||||
},
|
||||
"1": {
|
||||
"type": "number"
|
||||
},
|
||||
"2": {
|
||||
"type": "number"
|
||||
},
|
||||
"3": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1483,19 +1488,31 @@
|
||||
"goRuntime": {
|
||||
"type": "object",
|
||||
"keys": {
|
||||
"heapMB": {
|
||||
"type": "number"
|
||||
},
|
||||
"sysMB": {
|
||||
"type": "number"
|
||||
},
|
||||
"numGoroutine": {
|
||||
"goroutines": {
|
||||
"type": "number"
|
||||
},
|
||||
"numGC": {
|
||||
"type": "number"
|
||||
},
|
||||
"gcPauseMs": {
|
||||
"pauseTotalMs": {
|
||||
"type": "number"
|
||||
},
|
||||
"lastPauseMs": {
|
||||
"type": "number"
|
||||
},
|
||||
"heapAllocMB": {
|
||||
"type": "number"
|
||||
},
|
||||
"heapSysMB": {
|
||||
"type": "number"
|
||||
},
|
||||
"heapInuseMB": {
|
||||
"type": "number"
|
||||
},
|
||||
"heapIdleMB": {
|
||||
"type": "number"
|
||||
},
|
||||
"numCPU": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,8 +179,8 @@ func TestBroadcastFullBuffer(t *testing.T) {
|
||||
func TestBroadcastMarshalError(t *testing.T) {
|
||||
hub := NewHub()
|
||||
|
||||
// Marshal error: channels can't be marshaled
|
||||
hub.Broadcast(make(chan int))
|
||||
// Marshal error: functions can't be marshaled to JSON
|
||||
hub.Broadcast(map[string]interface{}{"bad": func() {}})
|
||||
// Should not panic — just log and return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user