fix(tests): eliminate tarpit OOM from global asyncio.sleep mock
Two interacting bugs caused asyncio.sleep to be mocked globally, letting tarpit_watcher_worker spin the event loop on a non-async mock and accumulate _increment_mock_call records without bound: 1. test_ingester.py patched `decnet.web.ingester.asyncio.sleep` via the asyncio singleton — any code in the process using asyncio.sleep (including the tarpit worker) hit the fake_sleep side_effect. Fix: add `_sleep = asyncio.sleep` alias in ingester.py and patch `decnet.web.ingester._sleep` instead — scopes the mock to ingester. 2. test_api_startup_guards.py called `_run_lifespan_startup` without DECNET_CONTRACT_TEST=true, which started the real tarpit task in a manually-constructed event loop that the tests never cancelled. Fix: set DECNET_CONTRACT_TEST=true inside _run_lifespan_startup so the lifespan skips all background workers.
This commit is contained in:
@@ -30,17 +30,26 @@ def _strip_pytest_vars(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
async def _run_lifespan_startup(api_mod) -> None:
|
||||
"""Run the lifespan up to (but not past) yield, then unwind cleanly."""
|
||||
app = FastAPI()
|
||||
cm = api_mod.lifespan(app)
|
||||
await cm.__aenter__()
|
||||
"""Run the lifespan up to (but not past) yield, then unwind cleanly.
|
||||
|
||||
DECNET_CONTRACT_TEST suppresses all background workers (ingestion,
|
||||
collector, TTP, tarpit) so no tasks escape test teardown.
|
||||
"""
|
||||
import os
|
||||
os.environ["DECNET_CONTRACT_TEST"] = "true"
|
||||
try:
|
||||
return
|
||||
finally:
|
||||
app = FastAPI()
|
||||
cm = api_mod.lifespan(app)
|
||||
await cm.__aenter__()
|
||||
try:
|
||||
await cm.__aexit__(None, None, None)
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
finally:
|
||||
try:
|
||||
await cm.__aexit__(None, None, None)
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
os.environ.pop("DECNET_CONTRACT_TEST", None)
|
||||
|
||||
|
||||
def test_master_api_refuses_to_start_in_agent_mode(
|
||||
|
||||
Reference in New Issue
Block a user