diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index 5a27e1904..9b15c8a65 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -1,4 +1,3 @@ -import asyncio import contextlib import time from collections.abc import Iterator @@ -38,6 +37,7 @@ async def test_contextmanager_in_threadpool() -> None: @pytest.mark.anyio +@pytest.mark.timeout(10, func_only=True) @pytest.mark.usefixtures("reset_teardown_limiter") async def test_competing_acquire_release() -> None: """Check that the main threadpool does not block the teardown threadpool.""" @@ -64,8 +64,6 @@ async def test_competing_acquire_release() -> None: # The threadpool should now be full of threads waiting to acquire # The release function should be able to run without being blocked by acquires - await asyncio.wait_for( - concurrency.run_in_teardown_threadpool(release), timeout=10 - ) + await concurrency.run_in_teardown_threadpool(release) assert len(acquired) == pool_size diff --git a/tests/test_depends_deadlock.py b/tests/test_depends_deadlock.py index 76e44cf68..bf9d4da9f 100644 --- a/tests/test_depends_deadlock.py +++ b/tests/test_depends_deadlock.py @@ -3,6 +3,7 @@ import threading import time from collections.abc import Iterator +import pytest from fastapi import Depends, FastAPI from httpx import ASGITransport, AsyncClient from pydantic import BaseModel @@ -42,6 +43,7 @@ def get_deadlock(dep: None = Depends(release_resource)) -> Item: # Fire off 100 requests in parallel(ish) in order to create contention # over the shared resource (simulating a fastapi server that interacts with # a database connection pool). +@pytest.mark.timeout(10, func_only=True) def test_depends_deadlock() -> None: async def make_request(client: AsyncClient): await client.get("/deadlock") @@ -53,4 +55,4 @@ def test_depends_deadlock() -> None: tasks = [make_request(aclient) for _ in range(100)] await asyncio.gather(*tasks) - asyncio.run(asyncio.wait_for(run_requests(), timeout=10)) + asyncio.run(run_requests())