fix(perception): keep cyclic GC outside realtime loop
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import importlib.util
|
||||
import time
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from k1link.perception.detector import DetectorFrameTiming
|
||||
from k1link.perception.recorded_source import DecodedFrameTiming
|
||||
@@ -108,3 +109,34 @@ def test_gc_pause_telemetry_attributes_collection_to_active_stage() -> None:
|
||||
}
|
||||
]
|
||||
assert summary["maximum_event"]["duration_ms"] >= 1.0
|
||||
|
||||
|
||||
def test_cyclic_gc_policy_collects_outside_hot_loop_and_restores_state() -> None:
|
||||
state = {"enabled": True}
|
||||
collections = iter((3, 0))
|
||||
|
||||
def disable() -> None:
|
||||
state["enabled"] = False
|
||||
|
||||
def enable() -> None:
|
||||
state["enabled"] = True
|
||||
|
||||
with (
|
||||
patch.object(RUNNER.gc, "isenabled", side_effect=lambda: state["enabled"]),
|
||||
patch.object(RUNNER.gc, "disable", side_effect=disable),
|
||||
patch.object(RUNNER.gc, "enable", side_effect=enable),
|
||||
patch.object(RUNNER.gc, "collect", side_effect=lambda: next(collections)),
|
||||
):
|
||||
policy = RUNNER.CyclicGcHotLoopPolicy()
|
||||
with policy:
|
||||
assert state["enabled"] is False
|
||||
|
||||
assert state["enabled"] is True
|
||||
assert policy.to_dict() == {
|
||||
"schema_version": RUNNER.GC_POLICY_SCHEMA,
|
||||
"enabled_before": True,
|
||||
"disabled_during_hot_loop": True,
|
||||
"enabled_after": True,
|
||||
"pre_collected": 3,
|
||||
"post_collected": 0,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user