perf(monitor): aggregate realtime workspace

This commit is contained in:
lingniu
2026-07-16 03:26:14 +08:00
parent 01150844df
commit cad39d6326
12 changed files with 147 additions and 28 deletions

View File

@@ -291,6 +291,26 @@ func TestMonitorMapTenThousandVehiclesNeverReturnsTenThousandPoints(t *testing.T
}
}
func TestMonitorWorkspaceSharesOneRealtimeSnapshot(t *testing.T) {
store := newCountingStore()
service := NewService(store)
workspace, err := service.MonitorWorkspace(context.Background(), url.Values{
"zoom": {"13"}, "railLimit": {"2"},
})
if err != nil {
t.Fatalf("MonitorWorkspace returned error: %v", err)
}
if store.vehicleRealtimeCalls != 1 {
t.Fatalf("workspace should read one realtime snapshot, calls=%d", store.vehicleRealtimeCalls)
}
if workspace.Summary.TotalVehicles == 0 || workspace.Map.Total == 0 {
t.Fatalf("workspace should derive summary and map from the shared snapshot: %+v", workspace)
}
if len(workspace.Vehicles.Items) != 2 || workspace.Vehicles.Limit != 2 || workspace.Vehicles.Total < 2 {
t.Fatalf("workspace rail page should honor its bounded limit: %+v", workspace.Vehicles)
}
}
func TestMonitorMapUsesMeaningfulClustersAndReleasesPointsAtDetailZoom(t *testing.T) {
vehicles := Page[VehicleRealtimeRow]{Items: []VehicleRealtimeRow{
{VIN: "NEAR-1", Plate: "粤A00001", Online: true, Longitude: 113.260, Latitude: 23.130},