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)
| 34 | |
| 35 | |
| 36 | def _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 | |
| 55 | def test_stale_entry_served_while_a_reload_is_in_flight(tmp_path): |
no outgoing calls
no test coverage detected