locustfile_backend.py 1.2 KB

123456789101112131415161718192021222324252627282930
  1. from locust import HttpUser, between, task
  2. class ServicePilotBackendUser(HttpUser):
  3. wait_time = between(1, 3)
  4. @task(5)
  5. def health_check(self):
  6. with self.client.get("/api/health", name="API-健康检查", catch_response=True) as response:
  7. if response.status_code == 200 and response.json().get("status") == "ok":
  8. response.success()
  9. else:
  10. response.failure(f"unexpected health response: {response.status_code}")
  11. @task(3)
  12. def parse_config(self):
  13. with self.client.get("/api/config/parse", name="API-Parse配置", catch_response=True) as response:
  14. if response.status_code == 200 and "serverUrl" in response.text:
  15. response.success()
  16. else:
  17. response.failure(f"unexpected config response: {response.status_code}")
  18. @task(1)
  19. def not_found_contract(self):
  20. with self.client.get("/api/unknown-resource", name="API-404契约", catch_response=True) as response:
  21. if response.status_code == 404:
  22. response.success()
  23. else:
  24. response.failure(f"expected 404, got {response.status_code}")