diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 77118c42e3..45eb78b9de 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -11,6 +11,7 @@ jobs: tests: name: "Python ${{ matrix.python-version }}" runs-on: "ubuntu-latest" + timeout-minutes: 15 strategy: matrix: diff --git a/pyproject.toml b/pyproject.toml index f2c19ab095..5d0225e935 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -116,6 +116,7 @@ check_untyped_defs = true [tool.pytest.ini_options] addopts = "-rxXs" +faulthandler_timeout = 60 filterwarnings = [ "error", # Until https://github.com/encode/httpcore/pull/1119 fixes https://github.com/encode/httpx/issues/3597. diff --git a/tests/conftest.py b/tests/conftest.py index 858bca1397..8df31016d9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -269,15 +269,28 @@ async def watch_restarts(self) -> None: # pragma: no cover def serve_in_thread(server: TestServer) -> typing.Iterator[TestServer]: - thread = threading.Thread(target=server.run) + thread = threading.Thread(target=server.run, daemon=True) + startup_deadline = time.monotonic() + 10 thread.start() try: while not server.started: + if not thread.is_alive(): + raise RuntimeError( # pragma: no cover + "Uvicorn test server exited before startup." + ) + if time.monotonic() > startup_deadline: + raise TimeoutError( # pragma: no cover + "Uvicorn test server did not start within 10 seconds." + ) time.sleep(1e-3) yield server finally: server.should_exit = True - thread.join() + thread.join(timeout=5) + if thread.is_alive(): + raise TimeoutError( # pragma: no cover + "Uvicorn test server did not stop within 5 seconds." + ) @pytest.fixture(scope="session")