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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TwLhnueWrsK15wrieXE5m7
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "devplacepy"
|
name = "devplacepy"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
description = "DevPlace - The Developer Social Network"
|
description = "DevPlace - The Developer Social Network"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
# retoor <retoor@molodetz.nl>
|
# retoor <retoor@molodetz.nl>
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import itertools
|
import itertools
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
@@ -9,6 +8,7 @@ import pytest
|
|||||||
from devplacepy.database import get_table, init_db
|
from devplacepy.database import get_table, init_db
|
||||||
from devplacepy.services.containers import store
|
from devplacepy.services.containers import store
|
||||||
from devplacepy.services.containers.workspace import provision
|
from devplacepy.services.containers.workspace import provision
|
||||||
|
from tests.conftest import run_async
|
||||||
|
|
||||||
OWNER = "provision-owner"
|
OWNER = "provision-owner"
|
||||||
STATUSES = (
|
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):
|
def test_editor_ready_when_the_editor_port_accepts_connections(listener):
|
||||||
port = listener.getsockname()[1]
|
port = listener.getsockname()[1]
|
||||||
row = _instance(container_ip="127.0.0.1", editor_port=port)
|
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():
|
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]
|
port = probe.getsockname()[1]
|
||||||
probe.close()
|
probe.close()
|
||||||
row = _instance(container_ip="127.0.0.1", editor_port=port)
|
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):
|
def test_editor_ready_is_false_without_a_reachable_target(listener):
|
||||||
row = _instance(container_ip="", ports_json="[]")
|
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):
|
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:
|
if status == store.ST_RUNNING:
|
||||||
continue
|
continue
|
||||||
row = _instance(container_ip="127.0.0.1", editor_port=port, status=status)
|
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):
|
def test_editor_ready_is_false_while_suspended(listener):
|
||||||
@@ -149,7 +149,7 @@ def test_editor_ready_is_false_while_suspended(listener):
|
|||||||
row = _instance(
|
row = _instance(
|
||||||
container_ip="127.0.0.1", editor_port=port, suspended_at="2026-01-01T00:00:00"
|
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):
|
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": "[]",
|
"ports_json": "[]",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
view = asyncio.run(provision.view(instance))
|
view = run_async(provision.view(instance))
|
||||||
assert view["phase"] == provision.PHASE_READY
|
assert view["phase"] == provision.PHASE_READY
|
||||||
assert view["phase_label"] == "Ready"
|
assert view["phase_label"] == "Ready"
|
||||||
assert view["editor_ready"] is True
|
assert view["editor_ready"] is True
|
||||||
assert view["owner_uid"] == OWNER
|
assert view["owner_uid"] == OWNER
|
||||||
|
|
||||||
store.update_instance(instance["uid"], {"desired_state": store.DESIRED_STOPPED})
|
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["phase"] == provision.PHASE_STOPPING
|
||||||
assert view["editor_ready"] is True
|
assert view["editor_ready"] is True
|
||||||
|
|||||||
Reference in New Issue
Block a user