-
Install dependencies (if not already installed):
uv pip install -r requirements.txt # or use 'uv pip install .' if using pyproject.toml
-
Start the server:
uv run uvicorn app.main:app --reload
The server will be available at http://localhost:8000
To run all tests using pytest:
uv run pytest --capture=tee-sys --cov=app --cov=tests --cov-report=term-missing
To run load tests with Locust (WebSocket):
-
Install the required package (if not already installed):
uv pip install websocket-client
-
Start the FastAPI server in a separate terminal:
uv run uvicorn app.main:app --reload
-
Run Locust load test:
uv run locust -f locustfile.py --headless -u 10 -r 2 --run-time 30s --host http://localhost:8000
Parameter explanations:
-u
or--users
: Number of simulated users (WebSocket clients).-r
or--spawn-rate
: How many users to start per second.--run-time
: How long the test should run (e.g.,30s
,1m
,5m
).--host
: The base URL of your FastAPI server.--headless
: Runs Locust without the web UI, outputs results to the terminal.
After the test completes, Locust will print a summary of results (requests, failures, and statistics) in your terminal. Since the script uses a custom WebSocket client, detailed request stats may not appear unless custom event logging is added.
The Locust script uses a synchronous WebSocket client for compatibility with Locust's threading model.