aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/tests')
-rw-r--r--packages/meshbay-node/tests/conftest.py31
-rw-r--r--packages/meshbay-node/tests/test_connection_processes.py7
-rw-r--r--packages/meshbay-node/tests/test_packaging_win.py24
3 files changed, 62 insertions, 0 deletions
diff --git a/packages/meshbay-node/tests/conftest.py b/packages/meshbay-node/tests/conftest.py
index 32c9b3d..545528b 100644
--- a/packages/meshbay-node/tests/conftest.py
+++ b/packages/meshbay-node/tests/conftest.py
@@ -1,9 +1,11 @@
"""Shared fixtures and helpers for node tests."""
+import asyncio
import sys
from pathlib import Path
import pytest
+import pytest_asyncio
from meshbay_node.roots import RootSet
# ffmpeg / ffprobe run via asyncio.create_subprocess_exec, which needs the
@@ -17,6 +19,35 @@ needs_subprocess = pytest.mark.skipif(
"SelectorEventLoop for aiortc",
)
+# The other way round, for a test that starts processes and has no two aiortc
+# ends in one process: on Windows it runs on the loop the daemon itself runs
+# on. The loop is chosen per test through pytest-asyncio's loop factories;
+# a version without them leaves the selector loop in place, where such a test
+# cannot run.
+_LOOP_FACTORIES = hasattr(
+ getattr(pytest_asyncio.plugin, "PytestAsyncioSpecs", None), "pytest_asyncio_loop_factories")
+on_the_daemons_loop = [
+ pytest.mark.daemon_loop,
+ pytest.mark.skipif(
+ sys.platform == "win32" and not _LOOP_FACTORIES,
+ reason="starts processes, which needs the ProactorEventLoop: asked for through "
+ "pytest-asyncio's loop factories, which this version does not have"),
+]
+
+
+def pytest_configure(config):
+ config.addinivalue_line(
+ "markers", "daemon_loop: on Windows, run on the event loop the daemon runs on")
+
+
+@pytest.hookimpl(optionalhook=True)
+def pytest_asyncio_loop_factories(config, item):
+ """The event loop of each async test here: the one it always had, except
+ for a test marked `daemon_loop` on Windows."""
+ if sys.platform == "win32" and item.get_closest_marker("daemon_loop"):
+ return {"proactor": asyncio.ProactorEventLoop}
+ return {"default": asyncio.new_event_loop}
+
@pytest.fixture(autouse=True)
def _no_log_file_in_the_developers_profile(monkeypatch):
"""A test that runs the daemon's entry point must not open its log file.
diff --git a/packages/meshbay-node/tests/test_connection_processes.py b/packages/meshbay-node/tests/test_connection_processes.py
index 47aded0..ab9dfd3 100644
--- a/packages/meshbay-node/tests/test_connection_processes.py
+++ b/packages/meshbay-node/tests/test_connection_processes.py
@@ -27,6 +27,13 @@ from meshbay_node.transport.webrtc.channel import _get_remote_ip, _pack
from meshbay_node.transport.webrtc.workers import WorkerPool
from meshbay_node.transport.webrtc_server import WebRTCTransport
+from conftest import on_the_daemons_loop
+
+# The pool starts processes, which the loop the suite runs on under Windows
+# cannot do; the node's end of each connection is in one of them, so that
+# loop's reason (two aiortc ends in one process) does not apply here.
+pytestmark = on_the_daemons_loop
+
async def _until(test, seconds: float = 15.0) -> None:
for _ in range(int(seconds / 0.02)):
diff --git a/packages/meshbay-node/tests/test_packaging_win.py b/packages/meshbay-node/tests/test_packaging_win.py
index 6f6388e..69eefc8 100644
--- a/packages/meshbay-node/tests/test_packaging_win.py
+++ b/packages/meshbay-node/tests/test_packaging_win.py
@@ -369,6 +369,30 @@ def test_the_build_starts_the_frozen_daemon_not_only_its_help():
assert 'url = "http://127.0.0.1:1"' in smoke
+def test_the_build_starts_a_frozen_connection_process():
+ """Above one `connection_processes` a frozen node starts copies of itself,
+ `meshbay-node.exe webrtc-worker`. No source checkout takes that path and
+ the daemon's smoke test stops short of it: it never signs in to a hub,
+ which is when the processes start."""
+ build = (WIN / "build-node-runtime.ps1").read_text(encoding="utf-8")
+ step = build.split("smoke test: the frozen node as a connection process", 1)[1]
+ assert 'smoke-connection-process.py") $exe (Join-Path $OutDir "meshbay-nodew.exe")' in step
+ assert "if ($LASTEXITCODE -ne 0) { throw" in step
+ # The other end is the node's own modules, in the build interpreter: removed
+ # any earlier, the step has nothing to run with.
+ assert build.count("Remove-Item -Recurse -Force $BuildVenv") == 1
+ assert "Remove-Item -Recurse -Force $BuildVenv" in step
+
+ smoke = (WIN / "smoke-connection-process.py").read_text(encoding="utf-8")
+ assert 'workers._argv = lambda: [exe, "webrtc-worker"]' in smoke
+ # The words a frozen node starts itself with, and the ones it answers to.
+ node = ROOT / "packages" / "meshbay-node" / "src" / "meshbay_node"
+ assert 'return [sys.executable, "webrtc-worker"]' in (
+ node / "transport" / "webrtc" / "workers.py").read_text(encoding="utf-8")
+ assert 'if sys.argv[1:2] == ["webrtc-worker"]:' in (
+ node / "daemon.py").read_text(encoding="utf-8")
+
+
def _run_stop_node(tmp_path, dummy_name, localappdata):
"""stop-node.ps1 as setup runs it, with the process and task names swapped
for ones that belong to this test -- the real ones would stop the