diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..c953efa --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,47 @@ +name: Upload Package + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + release-build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive # Initializes and fetches submodules + fetch-depth: 0 # Needed for submodule hashes + + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install the liburing + run: | + cd libs + ./configure + make + sudo make install + + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v5 + with: + version: "0.6.2" + enable-cache: true + + - name: Build release distributions + run: | + uv sync --group dev + uv build -v --sdist + + - name: Upload distributions + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} # + run: | + uv run twine upload --verbose --repository testpypi dist/* diff --git a/tests/__init__.py b/tests/e2e/loop/__init__.py similarity index 100% rename from tests/__init__.py rename to tests/e2e/loop/__init__.py diff --git a/tests/conftest.py b/tests/e2e/loop/conftest.py similarity index 53% rename from tests/conftest.py rename to tests/e2e/loop/conftest.py index 3723ae9..4eeeaea 100644 --- a/tests/conftest.py +++ b/tests/e2e/loop/conftest.py @@ -1,17 +1,26 @@ import asyncio +import os +import tempfile from typing import cast import pytest +import pytest_asyncio from uringloop.loop import IouringProactorEventLoop, IouringProactorEventLoopPolicy -@pytest.fixture(scope="session", autouse=True) -def event_loop_policy(): +@pytest_asyncio.fixture(scope="package", autouse=True) +async def event_loop_policy(): asyncio.set_event_loop_policy(IouringProactorEventLoopPolicy()) +# TODO: remove pytest_asyncio warning @pytest.fixture def event_loop(): loop = asyncio.get_event_loop() yield cast(IouringProactorEventLoop, loop) loop.close() + +@pytest.fixture +def unix_socket_path(): + with tempfile.TemporaryDirectory() as f: + yield os.path.join(f, "test.sock") diff --git a/tests/e2e/test_subprocess.py b/tests/e2e/loop/test_subprocess.py similarity index 100% rename from tests/e2e/test_subprocess.py rename to tests/e2e/loop/test_subprocess.py diff --git a/tests/e2e/test_unix.py b/tests/e2e/loop/test_unix.py similarity index 100% rename from tests/e2e/test_unix.py rename to tests/e2e/loop/test_unix.py diff --git a/tests/e2e/__init__.py b/tests/e2e/proactor/__init__.py similarity index 100% rename from tests/e2e/__init__.py rename to tests/e2e/proactor/__init__.py diff --git a/tests/e2e/conftest.py b/tests/e2e/proactor/conftest.py similarity index 87% rename from tests/e2e/conftest.py rename to tests/e2e/proactor/conftest.py index b0058ef..0479a31 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/proactor/conftest.py @@ -91,6 +91,19 @@ async def _run_proactor_task(): await asyncio.sleep(0.1) task = loop.create_task(_run_proactor_task()) + + def stop_all_coro_if_raise_exception(task: asyncio.Task[None]): + if task.exception(): # If task failed + # Cancel all other tasks + for t in asyncio.all_tasks(loop): + if t != task and not t.done(): + t.cancel() + + loop.run_until_complete(loop.shutdown_asyncgens()) + + # Add failure callback + task.add_done_callback(stop_all_coro_if_raise_exception) + yield proactor # Cleanup diff --git a/tests/e2e/test_tcp.py b/tests/e2e/proactor/test_tcp.py similarity index 100% rename from tests/e2e/test_tcp.py rename to tests/e2e/proactor/test_tcp.py diff --git a/tests/e2e/test_udp.py b/tests/e2e/proactor/test_udp.py similarity index 100% rename from tests/e2e/test_udp.py rename to tests/e2e/proactor/test_udp.py