From: Sam Mirazi Date: Sun, 1 Jun 2025 06:49:27 +0000 (-0700) Subject: docs(TDD): Clarify FastAPI server execution and fix markdown for Phase 4 X-Git-Url: https://git.josue.xyz/?a=commitdiff_plain;h=96ba16f2ca2f784603a6e79f5980c823edb810b5;p=fastapi-vs-flask%2F.git docs(TDD): Clarify FastAPI server execution and fix markdown for Phase 4 This commit enhances the Technical Design Document (Design Docs/TDD.md) by providing explicit instructions for running the FastAPI server, pertinent to the completion of Phase 4 ("Green Implementation for FastAPI"). It also includes a minor markdown syntax correction. Key changes: - Added a dedicated markdown block in Phase 4 with the precise command `uvicorn app_fastapi.app:app --host 127.0.0.1 --port 8000` and context for running the FastAPI application. This makes the instruction more prominent and user-friendly. - Removed the previous, less visible comment `# Uvicorn will run this: uvicorn app_fastapi.app:app --port 8000` from within the FastAPI Python code example to avoid redundancy and improve clarity. - Corrected markdown code block specifiers (from ``` to ````) around the FastAPI example and the new instruction block to ensure correct rendering of the document. These changes make it easier for anyone following the TDD to manually start and test the FastAPI server as intended at the end of Phase 4, before proceeding to the benchmarking in Phase 5. --- diff --git a/Design Docs/TDD.md b/Design Docs/TDD.md index 71c232d..3a4aa1e 100644 --- a/Design Docs/TDD.md +++ b/Design Docs/TDD.md @@ -253,7 +253,7 @@ _Key Tasks_ - Includes an artificial `await asyncio.sleep(3)` (non-blocking). - Ensure `uvicorn` runs it on the port expected by the test (e.g., 8000). -```python +````python # app_fastapi/app.py (example) from fastapi import FastAPI, Response import asyncio @@ -266,8 +266,10 @@ async def home(): html = "

Slow FastAPI Demo

" return Response(content=html, media_type="text/html") -# Uvicorn will run this: uvicorn app_fastapi.app:app --port 8000 -``` +To run this FastAPI server manually from your project root (after ensuring `uvicorn` and `fastapi` are installed in your environment), use the following command: +```bash +uvicorn app_fastapi.app:app --host 127.0.0.1 --port 8000 +```` _Tests_ diff --git a/app_fastapi/__pycache__/app.cpython-312.pyc b/app_fastapi/__pycache__/app.cpython-312.pyc index 16396b3..a12b7f3 100644 Binary files a/app_fastapi/__pycache__/app.cpython-312.pyc and b/app_fastapi/__pycache__/app.cpython-312.pyc differ diff --git a/app_fastapi/app.py b/app_fastapi/app.py index bc0f0cf..8a1936c 100644 --- a/app_fastapi/app.py +++ b/app_fastapi/app.py @@ -7,5 +7,5 @@ app = FastAPI() @app.get("/") async def home(): await asyncio.sleep(3) # simulate slow work (non-blocking) - html = "

FastAPI Server: 3s Artificial Delay Demo

" + html = "

FastAPI Server: 3-Seconds Artificial Delay Demo

" return Response(content=html, media_type="text/html") \ No newline at end of file diff --git a/app_flask/flask_application.py b/app_flask/flask_application.py index 5da77ea..8dbca04 100644 --- a/app_flask/flask_application.py +++ b/app_flask/flask_application.py @@ -7,7 +7,7 @@ app = Flask(__name__) @app.route("/") def home(): time.sleep(3) # simulate slow work - html = "

Flask Server: 3s Artificial Delay Demo

" # Updated content + html = "

Flask Server: 3-Seconds Artificial Delay Demo

" # Updated content return Response(html, mimetype="text/html") if __name__ == "__main__": diff --git a/tests/test_fastapi_route.py b/tests/test_fastapi_route.py index 015dbd6..40ff1d2 100644 --- a/tests/test_fastapi_route.py +++ b/tests/test_fastapi_route.py @@ -49,7 +49,7 @@ async def test_home_returns_html_fastapi(): async with httpx.AsyncClient(timeout=10) as client: r = await client.get(f"http://{HOST}:{PORT}/") assert r.status_code == 200 - assert "

FastAPI Server: 3s Artificial Delay Demo

" in r.text # Expected content + assert "

FastAPI Server: 3-Seconds Artificial Delay Demo

" in r.text # Expected content finally: if server_process and server_process.is_alive(): server_process.terminate() # Send SIGTERM diff --git a/tests/test_flask_route.py b/tests/test_flask_route.py index 5185c79..1065743 100644 --- a/tests/test_flask_route.py +++ b/tests/test_flask_route.py @@ -27,7 +27,7 @@ def test_home_returns_html(): } r = httpx.get("http://127.0.0.1:3000/", timeout=10, headers=headers) assert r.status_code == 200 - assert "

Flask Server: 3s Artificial Delay Demo

" in r.text + assert "

Flask Server: 3-Seconds Artificial Delay Demo

" in r.text finally: proc.terminate() try: