fix(platform): count source online by protocol
This commit is contained in:
@@ -239,6 +239,10 @@ func (m *MockStore) VehicleServiceSummary(ctx context.Context) (VehicleServiceSu
|
||||
summary.IdentityRequiredVehicles++
|
||||
}
|
||||
}
|
||||
onlineByProtocol := map[string]bool{}
|
||||
for _, status := range row.SourceStatus {
|
||||
onlineByProtocol[status.Protocol] = status.Online
|
||||
}
|
||||
for _, protocol := range row.Protocols {
|
||||
current := protocolCounts[protocol]
|
||||
if current == nil {
|
||||
@@ -246,7 +250,7 @@ func (m *MockStore) VehicleServiceSummary(ctx context.Context) (VehicleServiceSu
|
||||
protocolCounts[protocol] = current
|
||||
}
|
||||
current.Total++
|
||||
if row.Online {
|
||||
if onlineByProtocol[protocol] {
|
||||
current.Online++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,3 +64,22 @@ func TestVehicleServiceOverviewsUsesBatchDataPath(t *testing.T) {
|
||||
t.Fatalf("batch overview should avoid per-keyword store calls, vehicles=%d realtime=%d", store.vehiclesCalls, store.vehicleRealtimeCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVehicleServiceSummaryCountsProtocolOnlineByProtocolSlot(t *testing.T) {
|
||||
service := NewService(NewMockStore())
|
||||
summary, err := service.VehicleServiceSummary(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("VehicleServiceSummary returned error: %v", err)
|
||||
}
|
||||
byProtocol := map[string]ProtocolStat{}
|
||||
for _, protocol := range summary.Protocols {
|
||||
byProtocol[protocol.Protocol] = protocol
|
||||
}
|
||||
gb32960 := byProtocol["GB32960"]
|
||||
if gb32960.Total != 2 {
|
||||
t.Fatalf("expected two GB32960 source slots, got %+v", gb32960)
|
||||
}
|
||||
if gb32960.Online != 1 {
|
||||
t.Fatalf("GB32960 online count must use GB32960 source status only, got %+v", gb32960)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user