From 6b9c48661afe5656c54f517a951934e1fa7f5efc Mon Sep 17 00:00:00 2001 From: retoor Date: Mon, 7 Sep 2026 16:27:15 +0200 Subject: [PATCH] Use the shared run_async test helper instead of bare asyncio.run in provision tests asyncio.run() opens and tears down its own event loop per call, bypassing the shared background loop tests/conftest.py's run_async uses to refresh the snapshot cache after each coroutine. Switch provision.py's editor_ready and view tests to run_async for consistency with the rest of the async test suite. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01TwLhnueWrsK15wrieXE5m7 --- pyproject.toml | 2 +- .../services/containers/workspace/provision.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ffa5293..448730a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "devplacepy" -version = "1.0.1" +version = "1.0.2" description = "DevPlace - The Developer Social Network" requires-python = ">=3.12" dependencies = [ diff --git a/tests/unit/services/containers/workspace/provision.py b/tests/unit/services/containers/workspace/provision.py index 45ad8c4..dde2506 100644 --- a/tests/unit/services/containers/workspace/provision.py +++ b/tests/unit/services/containers/workspace/provision.py @@ -1,6 +1,5 @@ # retoor -import asyncio import itertools import socket @@ -9,6 +8,7 @@ import pytest from devplacepy.database import get_table, init_db from devplacepy.services.containers import store from devplacepy.services.containers.workspace import provision +from tests.conftest import run_async OWNER = "provision-owner" STATUSES = ( @@ -118,7 +118,7 @@ def test_transitional_phases_are_exactly_starting_and_stopping(): def test_editor_ready_when_the_editor_port_accepts_connections(listener): port = listener.getsockname()[1] row = _instance(container_ip="127.0.0.1", editor_port=port) - assert asyncio.run(provision.editor_ready(row)) is True + assert run_async(provision.editor_ready(row)) is True def test_editor_ready_is_false_when_nothing_listens(): @@ -127,12 +127,12 @@ def test_editor_ready_is_false_when_nothing_listens(): port = probe.getsockname()[1] probe.close() row = _instance(container_ip="127.0.0.1", editor_port=port) - assert asyncio.run(provision.editor_ready(row)) is False + assert run_async(provision.editor_ready(row)) is False def test_editor_ready_is_false_without_a_reachable_target(listener): row = _instance(container_ip="", ports_json="[]") - assert asyncio.run(provision.editor_ready(row)) is False + assert run_async(provision.editor_ready(row)) is False def test_editor_ready_is_false_unless_the_container_runs(listener): @@ -141,7 +141,7 @@ def test_editor_ready_is_false_unless_the_container_runs(listener): if status == store.ST_RUNNING: continue row = _instance(container_ip="127.0.0.1", editor_port=port, status=status) - assert asyncio.run(provision.editor_ready(row)) is False + assert run_async(provision.editor_ready(row)) is False def test_editor_ready_is_false_while_suspended(listener): @@ -149,7 +149,7 @@ def test_editor_ready_is_false_while_suspended(listener): row = _instance( container_ip="127.0.0.1", editor_port=port, suspended_at="2026-01-01T00:00:00" ) - assert asyncio.run(provision.editor_ready(row)) is False + assert run_async(provision.editor_ready(row)) is False def test_view_carries_the_phase_its_label_readiness_and_the_owner(listener): @@ -167,13 +167,13 @@ def test_view_carries_the_phase_its_label_readiness_and_the_owner(listener): "ports_json": "[]", } ) - view = asyncio.run(provision.view(instance)) + view = run_async(provision.view(instance)) assert view["phase"] == provision.PHASE_READY assert view["phase_label"] == "Ready" assert view["editor_ready"] is True assert view["owner_uid"] == OWNER store.update_instance(instance["uid"], {"desired_state": store.DESIRED_STOPPED}) - view = asyncio.run(provision.view(store.get_instance(instance["uid"]))) + view = run_async(provision.view(store.get_instance(instance["uid"]))) assert view["phase"] == provision.PHASE_STOPPING assert view["editor_ready"] is True