migrate session handling to aioweb_tls/refactoring of helpers

This commit is contained in:
TPV committed 2026-07-17 20:06:37 -07:00
1 parent 3a8a12ac6e
commit 1441e7179c
10 files changed
+244 -295

No files matched your search

+8 -11
View File
@@ -1,11 +1,12 @@
"""unit test: execute_pagination honours a caller-supplied shared semaphore
run from the repo root:
uv run python tests/test_pagination_semaphore.py
uv run pytest tests/test_pagination_semaphore.py
offline — no network. A fake page func records peak concurrency so we can
assert the fan-out limit actually holds, both for the shared-semaphore path
(one instance capping many categories at once) and the default per-call path.
(one instance capping many categories at once) and a single call bounding one
category with its own semaphore.
"""
import asyncio
@@ -62,9 +63,10 @@ def test_shared_semaphore_caps_total_concurrency_across_categories():
assert state["peak"] <= limit, f"peak {state['peak']} exceeded shared limit {limit}"
def test_default_falls_back_to_max_concurrent_tasks():
"""Without a semaphore, max_concurrent_tasks still bounds a single call."""
def test_single_call_respects_its_semaphore():
"""A single call bounds its own fan-out to the supplied semaphore limit."""
limit = 2
state = {"live": 0, "peak": 0}
func = _make_tracking_func(state)
@@ -75,13 +77,8 @@ def test_default_falls_back_to_max_concurrent_tasks():
products_per_page=30,
func=func,
session=None,
max_concurrent_tasks=2,
semaphore=asyncio.Semaphore(limit),
)
asyncio.run(run())
assert state["peak"] <= 2, f"peak {state['peak']} exceeded max_concurrent_tasks 2"
test_shared_semaphore_caps_total_concurrency_across_categories()
test_default_falls_back_to_max_concurrent_tasks()
print("pagination semaphore test passed")
assert state["peak"] <= limit, f"peak {state['peak']} over limit {limit}"