Enable parallel and stress testing

This commit is contained in:
thePR0M3TH3AN
2025-07-01 15:37:52 -04:00
parent b480b02326
commit 1d580819e7
5 changed files with 46 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ bcrypt
bip85
pytest>=7.0
pytest-cov
pytest-xdist
portalocker>=2.8
nostr-sdk>=0.42.1
websocket-client==1.7.0

View File

@@ -5,3 +5,28 @@ import pytest
@pytest.fixture(autouse=True)
def mute_logging():
logging.getLogger().setLevel(logging.WARNING)
def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption(
"--stress",
action="store_true",
default=False,
help="run stress tests",
)
def pytest_configure(config: pytest.Config) -> None:
config.addinivalue_line("markers", "stress: long running stress tests")
def pytest_collection_modifyitems(
config: pytest.Config, items: list[pytest.Item]
) -> None:
if config.getoption("--stress"):
return
skip_stress = pytest.mark.skip(reason="need --stress option to run")
for item in items:
if "stress" in item.keywords:
item.add_marker(skip_stress)

View File

@@ -42,19 +42,20 @@ def _backup(dir_path: Path, loops: int, out: Queue) -> None:
out.put(repr(e))
@pytest.mark.parametrize("loops", [5, pytest.param(20, marks=pytest.mark.stress)])
@pytest.mark.parametrize("_", range(3))
def test_concurrency_stress(tmp_path: Path, _):
def test_concurrency_stress(tmp_path: Path, loops: int, _):
key = Fernet.generate_key()
enc = EncryptionManager(key, tmp_path)
Vault(enc, tmp_path).save_index({"counter": 0})
q: Queue = Queue()
procs = [
Process(target=_writer, args=(key, tmp_path, 20, q)),
Process(target=_writer, args=(key, tmp_path, 20, q)),
Process(target=_reader, args=(key, tmp_path, 20, q)),
Process(target=_reader, args=(key, tmp_path, 20, q)),
Process(target=_backup, args=(tmp_path, 20, q)),
Process(target=_writer, args=(key, tmp_path, loops, q)),
Process(target=_writer, args=(key, tmp_path, loops, q)),
Process(target=_reader, args=(key, tmp_path, loops, q)),
Process(target=_reader, args=(key, tmp_path, loops, q)),
Process(target=_backup, args=(tmp_path, loops, q)),
]
for p in procs: