""" Configuration file for ATS load testing scenarios. This file defines different test scenarios with varying load patterns to simulate real-world usage of the ATS application. """ import os from dataclasses import dataclass from typing import Dict, List, Optional @dataclass class TestScenario: """Defines a load test scenario.""" name: str description: str users: int spawn_rate: int run_time: str host: str user_classes: List[str] tags: List[str] login_credentials: Optional[Dict] = None class LoadTestConfig: """Configuration management for load testing scenarios.""" def __init__(self): self.base_host = os.getenv("ATS_HOST", "http://localhost:8000") self.scenarios = self._define_scenarios() def _define_scenarios(self) -> Dict[str, TestScenario]: """Define all available test scenarios.""" return { "smoke_test": TestScenario( name="Smoke Test", description="Quick sanity check with minimal load", users=5, spawn_rate=2, run_time="2m", host=self.base_host, user_classes=["PublicUser"], tags=["smoke", "quick"] ), "light_load": TestScenario( name="Light Load Test", description="Simulates normal daytime traffic", users=20, spawn_rate=5, run_time="5m", host=self.base_host, user_classes=["PublicUser", "AuthenticatedUser"], tags=["light", "normal"] ), "moderate_load": TestScenario( name="Moderate Load Test", description="Simulates peak traffic periods", users=50, spawn_rate=10, run_time="10m", host=self.base_host, user_classes=["PublicUser", "AuthenticatedUser", "APIUser"], tags=["moderate", "peak"] ), "heavy_load": TestScenario( name="Heavy Load Test", description="Stress test with high concurrent users", users=100, spawn_rate=20, run_time="15m", host=self.base_host, user_classes=["PublicUser", "AuthenticatedUser", "APIUser", "FileUploadUser"], tags=["heavy", "stress"] ), "api_focus": TestScenario( name="API Focus Test", description="Focus on API endpoint performance", users=30, spawn_rate=5, run_time="10m", host=self.base_host, user_classes=["APIUser"], tags=["api", "backend"] ), "file_upload_test": TestScenario( name="File Upload Test", description="Test file upload performance", users=15, spawn_rate=3, run_time="8m", host=self.base_host, user_classes=["FileUploadUser", "AuthenticatedUser"], tags=["upload", "files"] ), "authenticated_test": TestScenario( name="Authenticated User Test", description="Test authenticated user workflows", users=25, spawn_rate=5, run_time="8m", host=self.base_host, user_classes=["AuthenticatedUser"], tags=["authenticated", "users"], login_credentials={ "username": os.getenv("TEST_USERNAME", "testuser"), "password": os.getenv("TEST_PASSWORD", "testpass123") } ), "endurance_test": TestScenario( name="Endurance Test", description="Long-running stability test", users=30, spawn_rate=5, run_time="1h", host=self.base_host, user_classes=["PublicUser", "AuthenticatedUser", "APIUser"], tags=["endurance", "stability"] ) } def get_scenario(self, scenario_name: str) -> Optional[TestScenario]: """Get a specific test scenario by name.""" return self.scenarios.get(scenario_name) def list_scenarios(self) -> List[str]: """List all available scenario names.""" return list(self.scenarios.keys()) def get_scenarios_by_tag(self, tag: str) -> List[TestScenario]: """Get all scenarios with a specific tag.""" return [scenario for scenario in self.scenarios.values() if tag in scenario.tags] # Performance thresholds for alerting PERFORMANCE_THRESHOLDS = { "response_time_p95": 2000, # 95th percentile should be under 2 seconds "response_time_avg": 1000, # Average response time under 1 second "error_rate": 0.05, # Error rate under 5% "rps_minimum": 10, # Minimum requests per second } # Environment-specific configurations ENVIRONMENTS = { "development": { "host": "http://localhost:8000", "database": "postgresql://localhost:5432/kaauh_ats_dev", "redis": "redis://localhost:6379/0" }, "staging": { "host": "https://staging.kaauh.edu.sa", "database": os.getenv("STAGING_DB_URL"), "redis": os.getenv("STAGING_REDIS_URL") }, "production": { "host": "https://kaauh.edu.sa", "database": os.getenv("PROD_DB_URL"), "redis": os.getenv("PROD_REDIS_URL") } } # Test data generation settings TEST_DATA_CONFIG = { "job_count": 100, "user_count": 50, "application_count": 500, "file_size_mb": 2, "concurrent_uploads": 5 }