mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-07 14:37:55 +00:00
The shared static server handled one connection at a time. Chromium can open a speculative connection and never send a request, so every queued request waited behind it. Under parallel load a computed-style capture's navigation stalled for 30s and failed. Under CPU saturation, 4 of 12 captures stalled for about 29s each. Serve each connection on a daemon thread. The existing serve-this-worktree test now holds a silent connection open while it fetches, and times out against the serial server. The configuration reference's recorded source lines are unchanged.
59 lines
2 KiB
Python
59 lines
2 KiB
Python
"""Contract for the loopback static server the browser tests run against.
|
|
|
|
The server used to bind a fixed port and raise if it was taken, which errored
|
|
every collected test rather than the browser ones — so a second worktree
|
|
running its own suite took the whole session down with it.
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
import socket
|
|
import urllib.request
|
|
from urllib.parse import urlsplit
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def test_static_origin_is_published_for_node_subprocesses() -> None:
|
|
origin = os.environ.get("ODYSSEUS_TEST_STATIC_ORIGIN")
|
|
|
|
assert origin, "the session fixture must publish the origin it bound"
|
|
assert re.fullmatch(r"http://127\.0\.0\.1:\d+", origin)
|
|
|
|
|
|
def test_static_origin_does_not_reuse_the_application_port() -> None:
|
|
"""An ephemeral port keeps the suite and a running instance independent."""
|
|
|
|
origin = os.environ["ODYSSEUS_TEST_STATIC_ORIGIN"]
|
|
|
|
assert not origin.endswith(":7011")
|
|
|
|
|
|
def test_static_server_serves_this_worktree() -> None:
|
|
origin = os.environ["ODYSSEUS_TEST_STATIC_ORIGIN"]
|
|
address = urlsplit(origin)
|
|
|
|
# Chromium may open a speculative connection and never send a request;
|
|
# that must not stall the requests queued behind it.
|
|
with socket.create_connection((address.hostname, address.port), timeout=5), \
|
|
urllib.request.urlopen(f"{origin}/static/js/documentStats.js", timeout=5) as r:
|
|
assert r.status == 200
|
|
assert r.headers.get_content_type() == "application/javascript"
|
|
|
|
|
|
def test_no_test_hardcodes_the_static_server_origin() -> None:
|
|
"""Regression guard: a hardcoded port reintroduces the collision."""
|
|
|
|
needle = "page.goto(" + "'http://127.0.0.1:"
|
|
offenders = []
|
|
for path in sorted((ROOT / "tests").glob("*.py")):
|
|
if path.name == Path(__file__).name:
|
|
continue
|
|
if needle in path.read_text(encoding="utf-8"):
|
|
offenders.append(path.name)
|
|
|
|
assert offenders == [], (
|
|
"browser tests must read ODYSSEUS_TEST_STATIC_ORIGIN rather than a fixed port"
|
|
)
|