3proxy/tests/cases/units.py
Vladimir Dubrovin 30f6043160 Event loop: what is due called when waiting fails; units on Windows
looponce() called nothing due when waiting for the sockets failed,
returning at once: a caller waiting for a timer turned forever. What is
due is called all the same, and on Windows WSAEINTR is no failure, not
errno. looptest reports any failure to wait with its error; fibertest
starts Winsock, its loop could not be made without, and recurses into
half of a fiber's stack rather than most of it, which Windows takes
more of. The units case shows what a test which never finished wrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 22:03:20 +03:00

35 lines
1.5 KiB
Python

"""The event loop and fibers on their own: tests/looptest.c and
tests/fibertest.c, built by CMake next to the 3proxy binary, each run with
a few seeds. Skipped where they were not built (the Makefiles do not build
them)."""
import os
import subprocess
def run(t):
here = os.path.dirname(os.path.abspath(t.binary))
for unit in ("looptest", "fibertest"):
path = os.path.join(here, unit + (".exe" if os.name == "nt" else ""))
if not os.path.exists(path):
t.skip(f"{unit} is built by CMake only")
continue
for seed in ("1", "2", "3"):
try:
done = subprocess.run([path, seed], stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, timeout=120)
except subprocess.TimeoutExpired as exc:
out = (exc.output or b"").decode(errors="replace")
t.fail(f"{unit} {seed} finishes",
actual="last: " + (out.splitlines() or ["nothing"])[-1])
continue
out = done.stdout.decode(errors="replace")
for line in out.splitlines():
if line.startswith("ok "):
t.ok(f"{unit} {seed}: {line[3:]}")
elif line.startswith("FAIL "):
label, _, what = line[5:].partition(": ")
t.fail(f"{unit} {seed}: {label}", actual=what)
if done.returncode and "FAIL " not in out:
t.fail(f"{unit} {seed} exits cleanly", 0, done.returncode)