| """ |
| Load test for SolarWine API using Locust. |
| |
| Usage: |
| pip install locust |
| locust -f scripts/load_test.py --host https://solarwine-api.hf.space |
| |
| # Quick headless run (10 users, 5 min): |
| locust -f scripts/load_test.py --host https://solarwine-api.hf.space \ |
| --users 10 --spawn-rate 2 --run-time 5m --headless |
| |
| # Full stress test (50 users, 5 min): |
| locust -f scripts/load_test.py --host https://solarwine-api.hf.space \ |
| --users 50 --spawn-rate 5 --run-time 5m --headless |
| """ |
|
|
| from locust import HttpUser, task, between |
|
|
|
|
| class SolarWineUser(HttpUser): |
| """Simulates a frontend user browsing the SolarWine dashboard.""" |
|
|
| wait_time = between(1, 5) |
|
|
| |
|
|
| @task(10) |
| def health(self): |
| self.client.get("/api/health") |
|
|
| @task(8) |
| def weather_current(self): |
| self.client.get("/api/weather/current") |
|
|
| @task(6) |
| def sensor_snapshot(self): |
| self.client.get("/api/sensors/snapshot") |
|
|
| @task(5) |
| def energy_current(self): |
| self.client.get("/api/energy/current") |
|
|
| @task(4) |
| def data_sources(self): |
| self.client.get("/api/health/data-sources") |
|
|
| |
|
|
| @task(3) |
| def energy_daily(self): |
| from datetime import date |
| self.client.get(f"/api/energy/daily/{date.today()}") |
|
|
| @task(3) |
| def weather_history(self): |
| from datetime import date, timedelta |
| end = date.today() |
| start = end - timedelta(days=7) |
| self.client.get(f"/api/weather/history?start_date={start}&end_date={end}&format=rows") |
|
|
| @task(2) |
| def photosynthesis_current(self): |
| self.client.get("/api/photosynthesis/current") |
|
|
| @task(2) |
| def biology_rules(self): |
| self.client.get("/api/biology/rules") |
|
|
| @task(2) |
| def control_status(self): |
| self.client.get("/api/control/status") |
|
|
| @task(2) |
| def control_trackers(self): |
| self.client.get("/api/control/trackers") |
|
|
| @task(1) |
| def phenology(self): |
| self.client.get("/api/biology/phenology") |
|
|
| @task(1) |
| def chill_units(self): |
| self.client.get("/api/biology/chill-units?season_start=2025-11-01") |
|
|
| |
|
|
| @task(1) |
| def photosynthesis_forecast(self): |
| self.client.get("/api/photosynthesis/forecast") |
|
|
| @task(1) |
| def control_plan(self): |
| self.client.get("/api/control/plan") |
|
|
| @task(1) |
| def sensor_soil(self): |
| self.client.get("/api/sensors/soil-moisture?hours=168") |
|
|
| @task(1) |
| def sensor_rain(self): |
| self.client.get("/api/sensors/rain?hours=168") |
|
|