GeezerVison is showing github.com — test(capacity): skip system-manager tests when transient units denied · CortexLM/hypertrain@0f1840b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: tests/challenge/test_capacity_outer_v2.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -193,6 +193,7 @@ def test_request_metadata_rejects_without_tensor_allocation(tiny, tmp_path, monk | 193 | 193 | OuterRequest.parse(data) | 194 | 194 |
| 195 | 195 |
| | 196 | +@pytest.mark.usefixtures("systemd_manager") | 196 | 197 | def test_actual_bounded_outer_child_matches_original_signed_replay(tiny, tmp_path, monkeypatch): | 197 | 198 | from hypertrain.aggregator.core import OuterState | 198 | 199 | from hypertrain.aggregator.tape_v2 import TapeV2, make_tape, replay_tape | @@ -672,6 +673,7 @@ def test_genesis_authority_rejects_before_kernel(genesis_tiny, monkeypatch, atta | 672 | 673 | ).fetchone() | 673 | 674 |
| 674 | 675 |
| | 676 | +@pytest.mark.usefixtures("systemd_manager") | 675 | 677 | def test_actual_bounded_genesis_preparation_and_duplicate_debit( | 676 | 678 | genesis_tiny, tmp_path, monkeypatch | 677 | 679 | ): | |
Collapse file Copy file name to clipboardExpand all lines: tests/challenge/test_service_capacity_v2.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -716,6 +716,7 @@ def prior_bytes(path): | 716 | 716 | assert store._record_v2(run_id, "service-admission", "run") == prior | 717 | 717 |
| 718 | 718 |
| | 719 | +@pytest.mark.usefixtures("systemd_manager") | 719 | 720 | def test_real_capacity_launch_failure_keeps_debit_and_prevents_restart_rerun( | 720 | 721 | tiny, tmp_path, monkeypatch | 721 | 722 | ): | |
Collapse file Copy file name to clipboardExpand all lines: tests/conftest.py +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | import json | 4 | 4 | import os | | 5 | +import subprocess | | 6 | +import uuid | 5 | 7 | from pathlib import Path | 6 | 8 |
| 7 | 9 | import numpy as np | @@ -110,3 +112,38 @@ def corpus_dir(tmp_path_factory: pytest.TempPathFactory) -> Path: | 110 | 112 | d = build_corpus(tmp_path_factory.mktemp("corpus")) | 111 | 113 | os.environ["HYPERTRAIN_DATA_DIR"] = str(d) | 112 | 114 | return d | | 115 | + | | 116 | + | | 117 | +@pytest.fixture(scope="session") | | 118 | +def systemd_manager() -> None: | | 119 | + """Skip unless this user may start transient units on the system manager, as the product does. | | 120 | +
| | 121 | + Root that cannot is a broken host, not an unprivileged one: fail, so the heavy `native` job | | 122 | + (isolated root environment) can never turn green by skipping. | | 123 | + """ | | 124 | + try: | | 125 | + probe = subprocess.run( | | 126 | + [ | | 127 | + "systemd-run", | | 128 | + "--unit=ht-probe-" + uuid.uuid4().hex, | | 129 | + "--wait", | | 130 | + "--collect", | | 131 | + "--quiet", | | 132 | + "--no-ask-password", | | 133 | + "--property=MemoryMax=64M", | | 134 | + "--property=CPUQuota=50%", | | 135 | + "/bin/true", | | 136 | + ], | | 137 | + capture_output=True, | | 138 | + text=True, | | 139 | + timeout=30, | | 140 | + check=False, | | 141 | + ) | | 142 | + ok, reason = probe.returncode == 0, f"rc={probe.returncode} {probe.stderr.strip()[-500:]}" | | 143 | + except (OSError, subprocess.TimeoutExpired) as exc: | | 144 | + ok, reason = False, repr(exc) | | 145 | + if ok: | | 146 | + return | | 147 | + if os.geteuid() == 0: | | 148 | + pytest.fail(f"systemd-run as root failed: {reason}") | | 149 | + pytest.skip(f"system manager transient units unavailable: {reason}") |
Collapse file Copy file name to clipboardExpand all lines: tests/miner/test_capacity_runtime_v2.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -23,6 +23,7 @@ def small(monkeypatch, tmp_path): | 23 | 23 | return launch.CapacityAttempt("11" * 32, "22" * 32, tmp_path / "runtime.lock", lambda: True) | 24 | 24 |
| 25 | 25 |
| | 26 | +@pytest.mark.usefixtures("systemd_manager") | 26 | 27 | @pytest.mark.parametrize("mode", ["success", "oom", "cancel", "deadline"]) | 27 | 28 | def test_actual_small_kernel_attempt_and_cleanup(tmp_path, small, mode): | 28 | 29 | """Subscribe readiness before triggering real bounded command and await pidfd exit.""" | @@ -145,6 +146,7 @@ def test_missing_manager_permission_has_no_unbounded_fallback(tmp_path, small, m | 145 | 146 | assert not (tmp_path / "attempt/capacity-observed.json").exists() | 146 | 147 |
| 147 | 148 |
| | 149 | +@pytest.mark.usefixtures("systemd_manager") | 148 | 150 | def test_real_runner_parent_death_retains_absolute_manager_timer(tmp_path, small): | 149 | 151 | """Fork only a stdlib waiting controller; manager timer survives its SIGKILL.""" | 150 | 152 | path = str(tmp_path / "dead.sock") | |
Collapse file Copy file name to clipboardExpand all lines: tests/miner/test_island_launch_v2.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -304,6 +304,7 @@ def test_noisy_failure_retains_only_bounded_error_tail( | 304 | 304 | assert not (tmp_path / "published").exists() | 305 | 305 |
| 306 | 306 |
| | 307 | +@pytest.mark.usefixtures("systemd_manager") | 307 | 308 | def test_capacity_branch_uses_real_bounded_failure_before_publication(tmp_path, monkeypatch): | 308 | 309 | import os | 309 | 310 | import sys | |
Collapse file Copy file name to clipboardExpand all lines: tests/relay/test_transport_v2.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1822,6 +1822,7 @@ def test_image_archive_stdin_through_capture_and_native_shim(tmp_path: Path) -> | 1822 | 1822 | assert json.loads(journal.read_bytes()) == {"cluster": "hypertrain-v2-stream"} | 1823 | 1823 |
| 1824 | 1824 |
| | 1825 | +@pytest.mark.usefixtures("systemd_manager") | 1825 | 1826 | def test_launch_safety_independent_systemd_units(tmp_path: Path) -> None: | 1826 | 1827 | import json | 1827 | 1828 | import os | |
|