docs: show example for max entries test

This commit is contained in:
thePR0M3TH3AN
2025-07-03 22:13:01 -04:00
parent d2e845f98c
commit ae04e4c466
3 changed files with 17 additions and 4 deletions

View File

@@ -288,7 +288,7 @@ when a new snapshot is triggered. Use the `NOSTR_TEST_DELAY` environment
variable to control the delay between publishes when experimenting with large vaults. variable to control the delay between publishes when experimenting with large vaults.
```bash ```bash
NOSTR_TEST_DELAY=10 pytest -vv src/tests/test_nostr_index_size.py -m "desktop and network" pytest -vv -s -n 0 src/tests/test_nostr_index_size.py --desktop --max-entries=1000
``` ```
### Automatically Updating the Script Checksum ### Automatically Updating the Script Checksum

View File

@@ -20,6 +20,12 @@ def pytest_addoption(parser: pytest.Parser) -> None:
default=False, default=False,
help="run desktop-only tests", help="run desktop-only tests",
) )
parser.addoption(
"--max-entries",
type=int,
default=None,
help="maximum entries for nostr index size test",
)
def pytest_configure(config: pytest.Config) -> None: def pytest_configure(config: pytest.Config) -> None:

View File

@@ -24,7 +24,7 @@ from nostr.client import NostrClient, Kind, KindStandard
@pytest.mark.desktop @pytest.mark.desktop
@pytest.mark.network @pytest.mark.network
def test_nostr_index_size_limits(): def test_nostr_index_size_limits(pytestconfig: pytest.Config):
"""Manually explore maximum index size for Nostr backups.""" """Manually explore maximum index size for Nostr backups."""
seed = ( seed = (
"abandon abandon abandon abandon abandon abandon abandon " "abandon abandon abandon abandon abandon abandon abandon "
@@ -47,13 +47,16 @@ def test_nostr_index_size_limits():
entry_mgr = EntryManager(vault, backup_mgr) entry_mgr = EntryManager(vault, backup_mgr)
delay = float(os.getenv("NOSTR_TEST_DELAY", "5")) delay = float(os.getenv("NOSTR_TEST_DELAY", "5"))
max_entries = pytestconfig.getoption("--max-entries")
size = 16 size = 16
batch = 100 batch = 100
entry_count = 0 entry_count = 0
max_payload = 60 * 1024 max_payload = 60 * 1024
try: try:
while True: while max_entries is None or entry_count < max_entries:
for _ in range(batch): for _ in range(batch):
if max_entries is not None and entry_count >= max_entries:
break
entry_mgr.add_entry( entry_mgr.add_entry(
website_name=f"site-{entry_count + 1}", website_name=f"site-{entry_count + 1}",
length=12, length=12,
@@ -85,7 +88,11 @@ def test_nostr_index_size_limits():
) )
retrieved_ok = retrieved == encrypted retrieved_ok = retrieved == encrypted
results.append((entry_count, payload_size, True, retrieved_ok)) results.append((entry_count, payload_size, True, retrieved_ok))
if not retrieved_ok or payload_size > max_payload: if (
not retrieved_ok
or payload_size > max_payload
or (max_entries is not None and entry_count >= max_entries)
):
break break
size *= 2 size *= 2
except Exception: except Exception: