MCPcopy Index your code
hub / github.com/python/cpython / test_cache_exhaustion

Method test_cache_exhaustion

Lib/test/test_external_inspection.py:3445–3514  ·  view source on GitHub ↗

Test cache works when frame limit (1024) is exceeded. FRAME_CACHE_MAX_FRAMES=1024. With 1100 recursive frames, the cache can't store all of them but should still work.

(self)

Source from the content-addressed store, hash-verified

3443 "Test only runs on Linux with process_vm_readv support",
3444 )
3445 def test_cache_exhaustion(self):
3446 """Test cache works when frame limit (1024) is exceeded.
3447
3448 FRAME_CACHE_MAX_FRAMES=1024. With 1100 recursive frames,
3449 the cache can't store all of them but should still work.
3450 """
3451 # Use 1100 to exceed FRAME_CACHE_MAX_FRAMES=1024
3452 depth = 1100
3453 script_body = f"""\
3454import sys
3455sys.setrecursionlimit(2000)
3456
3457def recurse(n):
3458 if n <= 0:
3459 sock.sendall(b"ready")
3460 sock.recv(16) # wait for ack
3461 sock.sendall(b"ready2")
3462 sock.recv(16) # wait for done
3463 return
3464 recurse(n - 1)
3465
3466recurse({depth})
3467"""
3468
3469 with self._target_process(script_body) as (
3470 p,
3471 client_socket,
3472 make_unwinder,
3473 ):
3474 unwinder_cache = make_unwinder(cache_frames=True)
3475 unwinder_no_cache = make_unwinder(cache_frames=False)
3476
3477 frames_cached = self._sample_frames(
3478 client_socket,
3479 unwinder_cache,
3480 b"ready",
3481 b"ack",
3482 {"recurse"},
3483 expected_frames=1102,
3484 )
3485 # Sample again with no cache for comparison
3486 frames_no_cache = self._sample_frames(
3487 client_socket,
3488 unwinder_no_cache,
3489 b"ready2",
3490 b"done",
3491 {"recurse"},
3492 expected_frames=1102,
3493 )
3494
3495 self.assertIsNotNone(frames_cached)
3496 self.assertIsNotNone(frames_no_cache)
3497
3498 # Both should have many recurse frames (> 1024 limit)
3499 cached_count = [f.funcname for f in frames_cached].count("recurse")
3500 no_cache_count = [f.funcname for f in frames_no_cache].count("recurse")
3501
3502 self.assertGreater(

Callers

nothing calls this directly

Calls 6

_target_processMethod · 0.95
_sample_framesMethod · 0.95
assertIsNotNoneMethod · 0.80
assertGreaterMethod · 0.80
countMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected