78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from scripts.check_solver_runtime import PROBE_OK_PREFIX, RUNTIME_PREFIX, run_probe
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def test_solver_runtime_probe_reports_runtime_identity() -> None:
|
|
completed = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
str(ROOT / "scripts" / "check_solver_runtime.py"),
|
|
"--iterations",
|
|
"1",
|
|
"--timeout-seconds",
|
|
"30",
|
|
],
|
|
cwd=ROOT,
|
|
capture_output=True,
|
|
text=True,
|
|
encoding="utf-8",
|
|
errors="replace",
|
|
check=False,
|
|
timeout=60,
|
|
)
|
|
assert completed.returncode == 0, f"{completed.stdout}\n{completed.stderr}"
|
|
assert "solver runtime probe passed" in completed.stdout
|
|
assert PROBE_OK_PREFIX in completed.stdout
|
|
assert "runtimeIdentity" in completed.stdout
|
|
assert "baseExecutable" in completed.stdout
|
|
assert "ENABLE_USER_SITE" in completed.stdout
|
|
assert '"ortools"' in completed.stdout
|
|
assert '"numpy"' in completed.stdout
|
|
assert '"pandas"' in completed.stdout
|
|
assert '"path"' in completed.stdout
|
|
assert '"version"' in completed.stdout
|
|
|
|
|
|
def test_solver_runtime_probe_rejects_fatal_marker_even_with_exit_zero(capsys) -> None:
|
|
stdout = (
|
|
f'{RUNTIME_PREFIX} {{"runtimeIdentity":"fixture"}}\n'
|
|
f'{PROBE_OK_PREFIX} {{"runtimeIdentity":"fixture"}}\n'
|
|
)
|
|
completed = subprocess.CompletedProcess(
|
|
["probe"],
|
|
0,
|
|
stdout,
|
|
"Windows fatal exception: code 0xc0000139",
|
|
)
|
|
|
|
assert run_probe(1, runner=lambda *args, **kwargs: completed) == 1
|
|
captured = capsys.readouterr()
|
|
assert "fatal marker detected" in captured.err
|
|
assert "0xc0000139" in captured.err
|
|
|
|
|
|
def test_solver_runtime_probe_applies_internal_timeout(capsys) -> None:
|
|
calls: list[dict[str, object]] = []
|
|
|
|
def runner(*args: object, **kwargs: object) -> subprocess.CompletedProcess[str]:
|
|
calls.append(kwargs)
|
|
raise subprocess.TimeoutExpired(cmd=["probe"], timeout=2.5)
|
|
|
|
assert run_probe(1, timeout_seconds=2.5, runner=runner) == 1
|
|
assert calls[0]["timeout"] == 2.5
|
|
assert "timed out" in capsys.readouterr().err
|
|
|
|
|
|
def test_solver_runtime_probe_requires_identity_and_success_markers(capsys) -> None:
|
|
completed = subprocess.CompletedProcess(["probe"], 0, "imports loaded", "")
|
|
|
|
assert run_probe(1, runner=lambda *args, **kwargs: completed) == 1
|
|
assert "solver probe failed" in capsys.readouterr().err
|