From 79dd0ebf53dbcf3f34629382c0e367fc6afa8930 Mon Sep 17 00:00:00 2001 From: oliver Date: Sat, 20 Jun 2026 14:56:20 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20switch=20from=20asyncio.wait=5Ffor?= =?UTF-8?q?=20to=20pytest=20timeout=20in=20deadlock=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `wait_for` was causing the test suite to hang completely when running with `-n auto`. --- tests/test_concurrency.py | 6 ++---- tests/test_depends_deadlock.py | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) 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())