47 """Wait for server to become available with retry logic."""
48 url = f
"http://{config.host}:{config.port}/ping"
50 console.print(f
"Waiting for server at {url}...")
52 for attempt
in range(1, config.max_retries + 1):
54 with httpx.Client(timeout=config.timeout)
as client:
55 response = client.get(url)
56 if response.status_code == 200:
57 console.print(
"✓ Server is ready!", style=
"green")
59 except (httpx.ConnectError, httpx.TimeoutException):
60 delay = config.retry_delay * (2 ** (attempt - 1))
62 f
" Attempt {attempt}/{config.max_retries}: Not ready (retry in {delay:.1f}s)"
64 if attempt < config.max_retries:
66 except KeyboardInterrupt:
67 console.print(
"\nInterrupted by user", style=
"yellow")
68 _thread.interrupt_main()
71 console.print(
"✗ Server not reachable", style=
"red")
75def send_request(client: httpx.Client, url: str, config: TestConfig) -> RequestResult:
76 """Send HTTP GET request and measure response time."""
78 start_time = time.perf_counter()
79 response = client.get(url, timeout=config.timeout)
80 elapsed_ms = (time.perf_counter() - start_time) * 1000
83 success=response.status_code == 200,
84 status_code=response.status_code,
85 response_text=response.text.strip(),
86 response_time_ms=elapsed_ms,
88 except httpx.ConnectError:
89 return RequestResult(
False,
None,
None, 0.0,
"Connection refused")
90 except httpx.TimeoutException:
91 return RequestResult(
False,
None,
None, 0.0,
"Request timeout")
92 except KeyboardInterrupt:
93 _thread.interrupt_main()
95 except Exception
as e:
159 """Main entry point."""
160 parser = argparse.ArgumentParser(description=
"Test FastLED Network example")
161 parser.add_argument(
"--host", default=
"localhost", help=
"Server host")
162 parser.add_argument(
"--port", type=int, default=8080, help=
"Server port")
163 parser.add_argument(
"--requests", type=int, default=5, help=
"Number of requests")
164 args = parser.parse_args()
166 config =
TestConfig(host=args.host, port=args.port, num_requests=args.requests)
168 console.print(
"[bold]FastLED Network Example Test Client[/bold]")
169 console.print(f
"Server: http://{config.host}:{config.port}\n")
173 console.print(
"\nERROR: Server not available", style=
"red bold")
174 console.print(
"\nTroubleshooting:")
175 console.print(
"1. Compile: bash compile posix --examples Server")
176 console.print(
"2. Run: .build/meson-quick/examples/Server.exe")
185 return 0
if all(r.success
for r
in results)
else 1