Spaces:
Sleeping
Sleeping
| from locust import HttpUser, task, between, events | |
| import logging | |
| import random | |
| import string | |
| class VoiceForgeUser(HttpUser): | |
| wait_time = between(2, 5) | |
| token = None | |
| def on_start(self): | |
| """Register and Login on simulation start""" | |
| email = f"loadtest_{''.join(random.choices(string.ascii_lowercase, k=8))}@example.com" | |
| password = "LoadTestPass123!" | |
| # Register | |
| with self.client.post("/api/v1/auth/register", json={ | |
| "email": email, | |
| "password": password, | |
| "full_name": "Load Tester" | |
| }, catch_response=True) as response: | |
| if response.status_code == 400: # Already exists | |
| pass | |
| elif response.status_code != 200: | |
| response.failure(f"Registration failed: {response.text}") | |
| # Login | |
| with self.client.post("/api/v1/auth/login", data={ | |
| "username": email, | |
| "password": password | |
| }, catch_response=True) as response: | |
| if response.status_code == 200: | |
| self.token = response.json().get("access_token") | |
| else: | |
| response.failure(f"Login failed: {response.text}") | |
| def health_check(self): | |
| """Light load endpoint""" | |
| self.client.get("/health") | |
| def get_user_profile(self): | |
| """Authenticated endpoint check""" | |
| if self.token: | |
| headers = {"Authorization": f"Bearer {self.token}"} | |
| self.client.get("/api/v1/auth/me", headers=headers) | |
| def synthesis_preview(self): | |
| """Medium load: TTS Preview""" | |
| if self.token: | |
| headers = {"Authorization": f"Bearer {self.token}"} | |
| self.client.post("/api/v1/tts/preview", json={ | |
| "voice": "en-US-Neural2-F", | |
| "text": "Hello world" | |
| }, headers=headers) |