| 48 | |
| 49 | |
| 50 | class StressTestResults: |
| 51 | def __init__(self) -> None: |
| 52 | self.total_requests: int = 0 |
| 53 | self.successful_requests: int = 0 |
| 54 | self.failed_requests: int = 0 |
| 55 | self.connection_errors: int = 0 |
| 56 | self.timeout_errors: int = 0 |
| 57 | self.other_errors: int = 0 |
| 58 | self.response_times: list[float] = [] |
| 59 | self.lock: threading.Lock = threading.Lock() |
| 60 | |
| 61 | def record_success(self, response_time_ms: float): |
| 62 | with self.lock: |
| 63 | self.total_requests += 1 |
| 64 | self.successful_requests += 1 |
| 65 | self.response_times.append(response_time_ms) |
| 66 | |
| 67 | def record_failure(self, error_type: str): |
| 68 | with self.lock: |
| 69 | self.total_requests += 1 |
| 70 | self.failed_requests += 1 |
| 71 | if error_type == "connection": |
| 72 | self.connection_errors += 1 |
| 73 | elif error_type == "timeout": |
| 74 | self.timeout_errors += 1 |
| 75 | else: |
| 76 | self.other_errors += 1 |
| 77 | |
| 78 | |
| 79 | def start_server(config: StressTestConfig) -> subprocess.Popen[str]: |