Skip to content

Commit 35e785b

Browse files
committed
Handle test suite overrun timeouts
1 parent 84859a2 commit 35e785b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on: [push, pull_request]
55
jobs:
66
build:
77
runs-on: ubuntu-latest
8+
timeout-minutes: 5
89
services:
910
rabbitmq:
1011
image: rabbitmq
@@ -34,3 +35,4 @@ jobs:
3435
run: uv run basedpyright
3536
- name: Run tests
3637
run: uv run pytest
38+
timeout-minutes: 2

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ register = [
5555
broker = "pika://localhost:5672"
5656
journal = "pika://localhost:5672"
5757

58+
[tool.pytest.ini_options]
59+
timeout = 30
60+
5861
[tool.coverage.run]
5962
branch = true
6063
source = ["queueio"]

queueio/conftest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import threading
3+
from threading import Thread
4+
from time import sleep
5+
6+
import pytest
7+
8+
9+
def pytest_sessionstart(session):
10+
"""Ensure the test suite always exits."""
11+
timeout = float(session.config.getini("timeout")) + 5
12+
Thread(target=lambda: sleep(timeout) or os._exit(1), daemon=True).start()
13+
14+
15+
@pytest.fixture(autouse=True)
16+
def check_thread_cleanup():
17+
"""Ensure that threads are not left running."""
18+
initial_threads = set(threading.enumerate())
19+
yield
20+
final_threads = {t for t in threading.enumerate() if t.is_alive()}
21+
new_threads = final_threads - initial_threads
22+
23+
if new_threads:
24+
thread_info = []
25+
for thread in new_threads:
26+
daemon = "daemon" if thread.daemon else "non-daemon"
27+
thread_info.append(f" - {thread.name} ({daemon})")
28+
29+
pytest.fail(
30+
f"Test left {len(new_threads)} thread(s) running:\n"
31+
+ "\n".join(thread_info)
32+
)

0 commit comments

Comments
 (0)