[eric] tests: the marketplace job test keeps one event loop across its requests; a bare TestClient tore the loop down after the POST and the job never ticked on Windows (ENG-490)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
ciregenz
2026-09-07 10:58:28 -07:00
co-authored by Claude Fable 5.1
parent 7c053c324d
commit 7004555f85
+14 -13
View File
@@ -108,16 +108,17 @@ def test_the_routes_start_a_job_and_report_it(monkeypatch: Any) -> None:
from fastapi import FastAPI
app = FastAPI()
app.include_router(p_mp.marketplace.router, prefix="/api/marketplace")
client = TestClient(app)
assert client.post("/api/marketplace/install/start", json={"id": "nope"}).status_code == 404
started = client.post("/api/marketplace/install/start", json={"id": "git-graph"})
assert started.status_code == 200
job_id = started.json()["job_id"]
# The job runs on its own thread; a Windows runner took more than the old 1 s to schedule it.
for _ in range(500):
status = client.get(f"/api/marketplace/install/{job_id}").json()
if status["phase"] == "failed":
break
time.sleep(0.02)
assert status["phase"] == "failed" and status["error"] == "the download returned 404"
assert client.get("/api/marketplace/install/does-not-exist").status_code == 404
# As a context manager: a bare TestClient builds a NEW event loop per request and tears it down after the
# response, so the job task the route schedules got no tick on a Windows runner and stayed "downloading".
with TestClient(app) as client:
assert client.post("/api/marketplace/install/start", json={"id": "nope"}).status_code == 404
started = client.post("/api/marketplace/install/start", json={"id": "git-graph"})
assert started.status_code == 200
job_id = started.json()["job_id"]
for _ in range(500):
status = client.get(f"/api/marketplace/install/{job_id}").json()
if status["phase"] == "failed":
break
time.sleep(0.02)
assert status["phase"] == "failed" and status["error"] == "the download returned 404"
assert client.get("/api/marketplace/install/does-not-exist").status_code == 404