()
| 270 | |
| 271 | |
| 272 | def main() -> int: |
| 273 | parser = argparse.ArgumentParser( |
| 274 | description="Stress test FastLED Network HTTP server" |
| 275 | ) |
| 276 | parser.add_argument("--host", default="localhost", help="Server host") |
| 277 | parser.add_argument("--port", type=int, default=8080, help="Server port") |
| 278 | parser.add_argument( |
| 279 | "--connections", type=int, default=20, help="Number of concurrent connections" |
| 280 | ) |
| 281 | parser.add_argument( |
| 282 | "--requests", type=int, default=50, help="Number of sequential requests" |
| 283 | ) |
| 284 | args = parser.parse_args() |
| 285 | |
| 286 | config = StressTestConfig( |
| 287 | host=args.host, |
| 288 | port=args.port, |
| 289 | num_connections=args.connections, |
| 290 | num_requests=args.requests, |
| 291 | ) |
| 292 | |
| 293 | console.print("[bold]FastLED Network HTTP Server - Phase 3 Stress Test[/bold]") |
| 294 | console.print(f"Server: http://{config.host}:{config.port}\n") |
| 295 | |
| 296 | console.print("[cyan]Starting server...[/cyan]") |
| 297 | server_proc = start_server(config) |
| 298 | console.print("[green]✓ Server started and responding[/green]") |
| 299 | |
| 300 | results = StressTestResults() |
| 301 | |
| 302 | try: |
| 303 | # Test 1: Concurrent connections |
| 304 | stress_test_concurrent(config, results) |
| 305 | |
| 306 | # Test 2: Rapid sequential requests |
| 307 | stress_test_rapid(config, results) |
| 308 | |
| 309 | # Display results |
| 310 | exit_code = display_results(results) |
| 311 | |
| 312 | return exit_code |
| 313 | |
| 314 | except KeyboardInterrupt: |
| 315 | console.print("\n[yellow]Test interrupted by user[/yellow]") |
| 316 | _thread.interrupt_main() |
| 317 | return 130 |
| 318 | |
| 319 | finally: |
| 320 | console.print("\n[cyan]Stopping server...[/cyan]") |
| 321 | server_proc.terminate() |
| 322 | try: |
| 323 | server_proc.wait(timeout=5) |
| 324 | except subprocess.TimeoutExpired: |
| 325 | server_proc.kill() |
| 326 | console.print("[green]✓ Server stopped[/green]") |
| 327 | |
| 328 | |
| 329 | if __name__ == "__main__": |
no test coverage detected