Preserve scaling data and reject contaminated benchmark attempts
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
from types import ModuleType, SimpleNamespace
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def scaling(monkeypatch: pytest.MonkeyPatch) -> ModuleType:
|
||||
scripts = Path(__file__).resolve().parents[2] / "scripts"
|
||||
monkeypatch.syspath_prepend(str(scripts))
|
||||
spec = importlib.util.spec_from_file_location("scaling", scripts / "scaling.py")
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_retry_preserves_previous_raw_data(scaling: ModuleType, tmp_path: Path) -> None:
|
||||
base = {"variant": "base", "config": "1x1"}
|
||||
first = scaling.attempt_folder(tmp_path, base, 100, 1)
|
||||
(first / "k6.txt").write_text("failed attempt")
|
||||
second = scaling.attempt_folder(tmp_path, base, 100, 1)
|
||||
assert first != second
|
||||
assert (first / "k6.txt").read_text() == "failed attempt"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("recover", [False, True])
|
||||
def test_disturbed_runs_never_enter_summary(
|
||||
scaling: ModuleType, monkeypatch: pytest.MonkeyPatch, recover: bool
|
||||
) -> None:
|
||||
args = SimpleNamespace(
|
||||
base_env={}, out="unused", retries=1, pause=0, rates="100", rejected=Mock()
|
||||
)
|
||||
rejected = {"raw_dir": "attempt1", "disturbed": True, "saturated": False}
|
||||
accepted = {"raw_dir": "attempt2", "disturbed": False, "saturated": False}
|
||||
monkeypatch.setattr(scaling, "layout", lambda *_: ({}, {}))
|
||||
monkeypatch.setattr(scaling, "apply", lambda *_: {})
|
||||
monkeypatch.setattr(scaling, "deployment", lambda *_: [])
|
||||
monkeypatch.setattr(scaling, "wait_quiet", lambda *_: None)
|
||||
monkeypatch.setattr(
|
||||
scaling, "step", Mock(side_effect=[rejected, accepted if recover else rejected])
|
||||
)
|
||||
output = Mock()
|
||||
if recover:
|
||||
scaling.block(args, output, "1x1", "base", [1])
|
||||
output.writerows.assert_called_once_with([accepted])
|
||||
args.rejected.writerow.assert_called_once_with(rejected)
|
||||
else:
|
||||
with pytest.raises(SystemExit, match="exhausted retries"):
|
||||
scaling.block(args, output, "1x1", "base", [1])
|
||||
output.writerows.assert_not_called()
|
||||
assert args.rejected.writerow.call_count == 2
|
||||
Reference in New Issue
Block a user