|
55 | 55 | try: |
56 | 56 | from _remote_debugging import PROCESS_VM_READV_SUPPORTED |
57 | 57 | from _remote_debugging import RemoteUnwinder |
58 | | - from _remote_debugging import FrameInfo, CoroInfo, TaskInfo |
| 58 | + from _remote_debugging import FrameInfo, CoroInfo, TaskInfo, AwaitedInfo |
59 | 59 | except ImportError: |
60 | 60 | raise unittest.SkipTest( |
61 | 61 | "Test only runs when _remote_debugging is available" |
@@ -487,6 +487,23 @@ def _extract_coroutine_funcnames(self, trace): |
487 | 487 | for task in info.awaited_by |
488 | 488 | } |
489 | 489 |
|
| 490 | + @skip_if_not_supported |
| 491 | + def test_async_awaited_info(self): |
| 492 | + async def main(): |
| 493 | + task = asyncio.current_task() |
| 494 | + unwinder = RemoteUnwinder(os.getpid()) |
| 495 | + for method in (unwinder.get_async_stack_trace, |
| 496 | + unwinder.get_all_awaited_by): |
| 497 | + with self.subTest(method=method.__name__): |
| 498 | + info, = (info for info in method() |
| 499 | + if info.thread_id == threading.get_native_id()) |
| 500 | + self.assertIsInstance(info, AwaitedInfo) |
| 501 | + task_info, = info.awaited_by |
| 502 | + self.assertEqual(task_info.task_id, id(task)) |
| 503 | + self.assertEqual(task_info.task_name, task.get_name()) |
| 504 | + |
| 505 | + asyncio.run(main()) |
| 506 | + |
490 | 507 | @skip_if_not_supported |
491 | 508 | def test_long_task_name_is_truncated(self): |
492 | 509 | # gh-157788 |
@@ -520,6 +537,22 @@ async def rec(n): |
520 | 537 |
|
521 | 538 | self.assertEqual(asyncio.run(rec(3)), ["rec"] * 4) |
522 | 539 |
|
| 540 | + @skip_if_not_supported |
| 541 | + def test_future_waiter_has_empty_stack(self): |
| 542 | + async def main(): |
| 543 | + task = asyncio.current_task() |
| 544 | + future = asyncio.get_running_loop().create_future() |
| 545 | + asyncio.future_add_to_awaited_by(task, future) |
| 546 | + try: |
| 547 | + trace = RemoteUnwinder(os.getpid()).get_all_awaited_by() |
| 548 | + task_info = self._get_task_id_map(trace)[id(task)] |
| 549 | + self.assertEqual(task_info.awaited_by, [([], id(future))]) |
| 550 | + self.assertTrue(task_info.coroutine_stack[0].call_stack) |
| 551 | + finally: |
| 552 | + asyncio.future_discard_from_awaited_by(task, future) |
| 553 | + |
| 554 | + asyncio.run(main()) |
| 555 | + |
523 | 556 | @skip_if_not_supported |
524 | 557 | def test_async_generator_stack_is_not_truncated(self): |
525 | 558 | # gh-159620 |
@@ -663,6 +696,17 @@ async def main(): |
663 | 696 | stacks = self._extract_coroutine_funcnames(asyncio.run(main())) |
664 | 697 | self.assertEqual(stacks["consumer"], ["consumer"]) |
665 | 698 |
|
| 699 | + @skip_if_not_supported |
| 700 | + def test_self_trace_with_empty_linetable(self): |
| 701 | + def sample(): |
| 702 | + return RemoteUnwinder(os.getpid()).get_stack_trace() |
| 703 | + |
| 704 | + sample.__code__ = sample.__code__.replace(co_linetable=b"") |
| 705 | + frame = self._find_frame_in_trace( |
| 706 | + sample(), lambda f: f.funcname == sample.__qualname__ |
| 707 | + ) |
| 708 | + self.assertEqual(frame.location, (-1, -1, -1, -1)) |
| 709 | + |
666 | 710 | @skip_if_not_supported |
667 | 711 | @unittest.skipIf( |
668 | 712 | sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED, |
|
0 commit comments