Skip to content

The agent that grows with you

test(config): guard the lock-free read_raw_config fast path

kshitijk4poor018b05628048
diff --git a/tests/hermes_cli/test_config_lock_free_cache_hit.py b/tests/hermes_cli/test_config_lock_free_cache_hit.py
index a5a09b28e93..682c0f7a148 100644
--- a/tests/hermes_cli/test_config_lock_free_cache_hit.py
+++ b/tests/hermes_cli/test_config_lock_free_cache_hit.py
@@ -39,8 +39,10 @@ def config_home(tmp_path, monkeypatch):
from hermes_cli import config as cfgmod
cfgmod._LOAD_CONFIG_CACHE.clear()
+ cfgmod._RAW_CONFIG_CACHE.clear()
yield home
cfgmod._LOAD_CONFIG_CACHE.clear()
+ cfgmod._RAW_CONFIG_CACHE.clear()
def _bump_mtime(path):
@@ -48,10 +50,12 @@ def _bump_mtime(path):
os.utime(path, ns=(st.st_atime_ns, st.st_mtime_ns + 1_000_000))
-def test_cached_read_completes_while_another_thread_holds_the_config_lock(config_home):
+def _time_cached_read_under_held_lock(reader):
+ """Prime ``reader`` (lock-free), then time one more call while another thread holds
+ ``_CONFIG_LOCK``. Returns ``(result, elapsed_seconds)``."""
from hermes_cli import config as cfgmod
- cfgmod.load_config_readonly() # prime the cache
+ reader() # prime the cache
holding = threading.Event()
release = threading.Event()
@@ -66,11 +70,18 @@ def test_cached_read_completes_while_another_thread_holds_the_config_lock(config
try:
assert holding.wait(timeout=10), "lock holder never started"
started = time.perf_counter()
- cfg = cfgmod.load_config_readonly()
+ result = reader()
elapsed = time.perf_counter() - started
finally:
release.set()
thread.join(timeout=10)
+ return result, elapsed
+
+
+def test_cached_read_completes_while_another_thread_holds_the_config_lock(config_home):
+ from hermes_cli import config as cfgmod
+
+ cfg, elapsed = _time_cached_read_under_held_lock(cfgmod.load_config_readonly)
assert isinstance(cfg, dict) and cfg
assert elapsed < MAX_BLOCKED_READ_SECS, (
@@ -79,6 +90,19 @@ def test_cached_read_completes_while_another_thread_holds_the_config_lock(config
)
+def test_cached_raw_read_completes_while_another_thread_holds_the_config_lock(config_home):
+ """Twin of the load_config test for the sibling ``read_raw_config`` fast path."""
+ from hermes_cli import config as cfgmod
+
+ raw, elapsed = _time_cached_read_under_held_lock(cfgmod.read_raw_config_readonly)
+
+ assert isinstance(raw, dict) and raw.get("plugins") == {"hook_callback_timeout": 30}
+ assert elapsed < MAX_BLOCKED_READ_SECS, (
+ f"a cached read_raw_config_readonly() blocked {elapsed:.1f}s behind a held "
+ "_CONFIG_LOCK; cache hits must not serialize against config writers"
+ )
+
+
def test_hook_timeout_does_not_read_config_on_every_invocation(config_home):
from hermes_cli import config as cfgmod
from hermes_cli import plugins as pluginsmod