File size: 3,336 Bytes
aef804e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | """
Shared fixtures for load testing with Locust.
This module provides pytest fixtures and configuration for load testing.
Fixtures provide test data (user credentials, agent IDs, workflow IDs) and
configuration for Locust load test scenarios.
Reference: Phase 209 Plan 01 - Locust Load Testing Infrastructure
"""
import pytest
import random
import string
from typing import Dict, List, Any
@pytest.fixture(scope="session")
def load_test_config() -> Dict[str, Any]:
"""
Load test configuration for Locust scenarios.
Provides default configuration values for load tests including
host URL, wait times, and authentication endpoints.
Returns:
Dict: Configuration dictionary with keys:
- host: Base URL for the application
- default_wait_min: Minimum wait time between tasks (seconds)
- default_wait_max: Maximum wait time between tasks (seconds)
- auth_endpoint: Authentication endpoint path
"""
return {
"host": "http://localhost:8000",
"default_wait_min": 1,
"default_wait_max": 3,
"auth_endpoint": "/api/v1/auth/login"
}
@pytest.fixture(scope="session")
def test_user_credentials() -> List[Dict[str, str]]:
"""
Test user credentials for load testing authentication.
Provides 10 test user accounts with consistent email format
and passwords. These users are used to simulate concurrent
authenticated load on the API.
Returns:
List[Dict]: List of user credential dictionaries with keys:
- email: User email address
- password: User password
"""
return [
{
"email": f"load_test_{i}@example.com",
"password": "test_password_123"
}
for i in range(10)
]
@pytest.fixture(scope="session")
def agent_ids() -> List[str]:
"""
Test agent IDs for load testing.
Provides 100 test agent IDs to simulate realistic agent
operations during load tests. Agent IDs follow a consistent
naming pattern for easy identification.
Returns:
List[str]: List of agent ID strings
"""
return [f"test_agent_{i:03d}" for i in range(100)]
@pytest.fixture(scope="session")
def workflow_ids() -> List[str]:
"""
Test workflow IDs for load testing.
Provides 20 test workflow IDs to simulate workflow execution
during load tests. Workflow IDs follow a consistent naming
pattern for easy identification.
Returns:
List[str]: List of workflow ID strings
"""
return [f"test_workflow_{i:03d}" for i in range(20)]
@pytest.fixture(scope="session")
def episode_ids() -> List[str]:
"""
Test episode IDs for load testing.
Provides 50 test episode IDs to simulate episode retrieval
operations during load tests. Episode IDs follow a consistent
naming pattern for easy identification.
Returns:
List[str]: List of episode ID strings
"""
return [f"test_episode_{i:03d}" for i in range(50)]
def generate_random_string(length: int = 10) -> str:
"""
Generate a random string for test data.
Args:
length: Length of the random string (default: 10)
Returns:
str: Random alphanumeric string
"""
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
|