MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _gate

Function _gate

tests/test_graph_context_cache_reload.py:36–52  ·  view source on GitHub ↗

Make `cache._load_entry` sleep `delay`s, counting every call. `slow_for` restricts the delay to paths whose resolved string contains it; every other path still uses the real (fast) loader.

(cache: _GraphContextCache, delay: float, slow_for=None)

Source from the content-addressed store, hash-verified

34
35
36def _gate(cache: _GraphContextCache, delay: float, slow_for=None):
37 """Make `cache._load_entry` sleep `delay`s, counting every call.
38
39 `slow_for` restricts the delay to paths whose resolved string contains it;
40 every other path still uses the real (fast) loader.
41 """
42 original = cache._load_entry
43 calls: list[tuple[str, tuple[int, int]]] = []
44
45 def gated(resolved_path, key):
46 calls.append((resolved_path, key))
47 if slow_for is None or slow_for in resolved_path:
48 time.sleep(delay)
49 return original(resolved_path, key)
50
51 cache._load_entry = gated
52 return calls
53
54
55def test_stale_entry_served_while_a_reload_is_in_flight(tmp_path):

Calls

no outgoing calls

Tested by

no test coverage detected