Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

test(server): freeze the session heap between test modules (#1038)

Krisztian Gajdarc2d100fb4d3d
diff --git a/packages/sie_server/tests/conftest.py b/packages/sie_server/tests/conftest.py
index 388a408b4..b2484af67 100644
--- a/packages/sie_server/tests/conftest.py
+++ b/packages/sie_server/tests/conftest.py
@@ -7,6 +7,7 @@ All server management is inline to avoid cross-package dependencies.
from __future__ import annotations
import contextlib
+import gc
import logging
import os
import signal
@@ -30,6 +31,14 @@ logger = logging.getLogger(__name__)
_project_root = Path(__file__).parent.parent.parent.parent
[email protected](scope="module", autouse=True)
+def _freeze_session_heap() -> None:
+ # Adapter.unload() runs a full gc.collect() whose cost grows with every
+ # object the session has accumulated; frozen objects are skipped.
+ gc.collect()
+ gc.freeze()
+
+
@pytest.fixture(scope="session")
def device() -> str:
"""Auto-detected device for integration tests (cuda:0, mps, or cpu)."""
diff --git a/packages/sie_server/tests/core/test_registry_load_oom.py b/packages/sie_server/tests/core/test_registry_load_oom.py
index 5d1881e46..9bcfd776a 100644
--- a/packages/sie_server/tests/core/test_registry_load_oom.py
+++ b/packages/sie_server/tests/core/test_registry_load_oom.py
@@ -179,6 +179,14 @@ def _stop_patches() -> Iterator[None]:
patch.stopall()
[email protected](autouse=True)
+def _collect_the_whole_heap() -> None:
+ # A failed load's memory is free only once the event loop task that
+ # received its exception has yielded. A collection over the whole heap
+ # takes long enough for that; one that skips frozen objects does not.
+ gc.unfreeze()
+
+
async def test_retry_runs_after_the_failed_attempt_is_released() -> None:
device = _Device(total_bytes=10 * GIB)
registry = await _registry(