fix AsyncClient usage

This commit is contained in:
svlandeg 2025-11-04 15:23:57 +01:00
parent 7240772ab9
commit a75414d733
1 changed files with 5 additions and 3 deletions

View File

@ -3,8 +3,8 @@ import threading
import time
from typing import Generator
import httpx
from fastapi import Depends, FastAPI
from httpx import ASGITransport, AsyncClient
from pydantic import BaseModel
app = FastAPI()
@ -66,11 +66,13 @@ def get_deadlock(db: MyDB = Depends(get_db)):
# able to free the resource without deadlocking, allowing each request to
# be handled timely
def test_depends_deadlock_patch():
async def make_request(client: httpx.AsyncClient):
async def make_request(client: AsyncClient):
await client.get("/deadlock")
async def run_requests():
async with httpx.AsyncClient(app=app, base_url="http://testserver") as aclient:
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://testserver"
) as aclient:
tasks = [make_request(aclient) for _ in range(100)]
await asyncio.gather(*tasks)