mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 07:18:47 +00:00
Enable parallel and stress testing
This commit is contained in:
11
.github/workflows/python-ci.yml
vendored
11
.github/workflows/python-ci.yml
vendored
@@ -5,6 +5,8 @@ on:
|
|||||||
branches: [ "**" ]
|
branches: [ "**" ]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "**" ]
|
branches: [ "**" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 3 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -19,6 +21,8 @@ jobs:
|
|||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
HYPOTHESIS_SEED: 123456
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v4
|
||||||
@@ -63,13 +67,18 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -r src/requirements.txt
|
pip install -r src/requirements.txt
|
||||||
|
- name: Determine stress args
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "schedule" ]; then
|
||||||
|
echo "STRESS_ARGS=--stress" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
- name: Enable Nostr network tests on main branch
|
- name: Enable Nostr network tests on main branch
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
run: echo "NOSTR_E2E=1" >> $GITHUB_ENV
|
run: echo "NOSTR_E2E=1" >> $GITHUB_ENV
|
||||||
- name: Run tests with coverage
|
- name: Run tests with coverage
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
pytest --cov=src --cov-report=xml --cov-report=term-missing \
|
pytest ${STRESS_ARGS} --cov=src --cov-report=xml --cov-report=term-missing \
|
||||||
--cov-fail-under=20 src/tests
|
--cov-fail-under=20 src/tests
|
||||||
- name: Upload coverage report
|
- name: Upload coverage report
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
[pytest]
|
[pytest]
|
||||||
|
addopts = -n auto
|
||||||
log_cli = true
|
log_cli = true
|
||||||
log_cli_level = WARNING
|
log_cli_level = WARNING
|
||||||
log_level = WARNING
|
log_level = WARNING
|
||||||
testpaths = src/tests
|
testpaths = src/tests
|
||||||
markers =
|
markers =
|
||||||
network: tests that require network connectivity
|
network: tests that require network connectivity
|
||||||
|
stress: long running stress tests
|
||||||
|
hypothesis_profile = ci
|
||||||
|
@@ -10,6 +10,7 @@ bcrypt
|
|||||||
bip85
|
bip85
|
||||||
pytest>=7.0
|
pytest>=7.0
|
||||||
pytest-cov
|
pytest-cov
|
||||||
|
pytest-xdist
|
||||||
portalocker>=2.8
|
portalocker>=2.8
|
||||||
nostr-sdk>=0.42.1
|
nostr-sdk>=0.42.1
|
||||||
websocket-client==1.7.0
|
websocket-client==1.7.0
|
||||||
|
@@ -5,3 +5,28 @@ import pytest
|
|||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def mute_logging():
|
def mute_logging():
|
||||||
logging.getLogger().setLevel(logging.WARNING)
|
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)
|
||||||
|
@@ -42,19 +42,20 @@ def _backup(dir_path: Path, loops: int, out: Queue) -> None:
|
|||||||
out.put(repr(e))
|
out.put(repr(e))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("loops", [5, pytest.param(20, marks=pytest.mark.stress)])
|
||||||
@pytest.mark.parametrize("_", range(3))
|
@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()
|
key = Fernet.generate_key()
|
||||||
enc = EncryptionManager(key, tmp_path)
|
enc = EncryptionManager(key, tmp_path)
|
||||||
Vault(enc, tmp_path).save_index({"counter": 0})
|
Vault(enc, tmp_path).save_index({"counter": 0})
|
||||||
|
|
||||||
q: Queue = Queue()
|
q: Queue = Queue()
|
||||||
procs = [
|
procs = [
|
||||||
Process(target=_writer, args=(key, tmp_path, 20, q)),
|
Process(target=_writer, args=(key, tmp_path, loops, q)),
|
||||||
Process(target=_writer, args=(key, tmp_path, 20, q)),
|
Process(target=_writer, args=(key, tmp_path, loops, q)),
|
||||||
Process(target=_reader, args=(key, tmp_path, 20, q)),
|
Process(target=_reader, args=(key, tmp_path, loops, q)),
|
||||||
Process(target=_reader, args=(key, tmp_path, 20, q)),
|
Process(target=_reader, args=(key, tmp_path, loops, q)),
|
||||||
Process(target=_backup, args=(tmp_path, 20, q)),
|
Process(target=_backup, args=(tmp_path, loops, q)),
|
||||||
]
|
]
|
||||||
|
|
||||||
for p in procs:
|
for p in procs:
|
||||||
|
Reference in New Issue
Block a user