Skip to content

Commit 17b4197

Browse files
committed
test truncation and linetable sentinel
1 parent 6736133 commit 17b4197

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

Lib/test/test_external_inspection.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,15 +3945,40 @@ def test_long_filename_truncated(self):
39453945
frame.filename, "x" * 1024 + "(len=1503)"
39463946
)
39473947

3948-
def test_large_linetable_keeps_line_numbers(self):
3949-
"""A linetable larger than the old 4096-byte cap keeps line numbers."""
3948+
def test_long_task_name_truncated(self):
3949+
"""An asyncio task name longer than 255 chars is truncated with a
3950+
marker instead of failing the whole sample."""
39503951
script_body = """\
3951-
body = "\\n".join(" x%d = %d" % (i, i) for i in range(4000))
3952+
import asyncio
3953+
3954+
async def worker():
3955+
sock.sendall(b"ready")
3956+
await asyncio.sleep(10_000)
3957+
3958+
async def main():
3959+
await asyncio.create_task(worker(), name="T" * 300)
3960+
3961+
asyncio.run(main())
3962+
"""
3963+
with self._running_target(script_body) as (p, client_socket):
3964+
_wait_for_signal(client_socket, b"ready")
3965+
names = [
3966+
task.task_name
3967+
for awaited_info in get_all_awaited_by(p.pid)
3968+
for task in awaited_info.awaited_by
3969+
]
3970+
self.assertIn("T" * 255 + "(len=300)", names)
3971+
3972+
def test_oversized_linetable_degrades_to_no_location(self):
3973+
"""A linetable over MAX_LINETABLE_SIZE degrades to a frame without
3974+
location instead of failing the whole sample."""
3975+
script_body = """\
3976+
body = " x = 1\\n" * 16_000
39523977
src = ("def big():\\n" + body + "\\n"
39533978
" sock.sendall(b'ready')\\n"
39543979
" time.sleep(10_000)\\n")
39553980
ns = {"sock": sock, "time": time}
3956-
exec(src, ns)
3981+
exec(compile(src, "big_linetable.py", "exec"), ns)
39573982
sock.sendall(b"lt:%d\\n" % len(ns["big"].__code__.co_linetable))
39583983
ns["big"]()
39593984
"""
@@ -3962,15 +3987,13 @@ def test_large_linetable_keeps_line_numbers(self):
39623987
linetable_size = int(
39633988
buffer.partition(b"lt:")[2].partition(b"\n")[0]
39643989
)
3965-
self.assertGreater(linetable_size, 4096)
3990+
self.assertGreater(linetable_size, 64 * 1024)
39663991

39673992
frame = self._sample_until_frame(
39683993
p.pid, lambda f: f.funcname == "big"
39693994
)
3970-
self.assertIsNotNone(
3971-
frame.location, "line info degraded for large linetable"
3972-
)
3973-
self.assertGreater(frame.location.lineno, 4000)
3995+
self.assertIsNone(frame.location)
3996+
self.assertEqual(frame.filename, "big_linetable.py")
39743997

39753998
@unittest.skipIf(
39763999
sys.platform == "win32",

0 commit comments

Comments
 (0)