Cover lines 251-256: CancelledError inside queue.get() wait. We cancel the outer consuming task while stream_execute_tools is blocked waiting for a result. The CancelledError propagates into the except branch, which cancels remaining tasks and breaks.
()
| 722 | |
| 723 | @pytest.mark.asyncio |
| 724 | async def test_stream_cancelled_error_path(): |
| 725 | """Cover lines 251-256: CancelledError inside queue.get() wait. |
| 726 | |
| 727 | We cancel the outer consuming task while stream_execute_tools is blocked |
| 728 | waiting for a result. The CancelledError propagates into the except branch, |
| 729 | which cancels remaining tasks and breaks. |
| 730 | """ |
| 731 | manager = SlowMockToolManager(default_delay=10.0) # all tools are very slow |
| 732 | calls = [ |
| 733 | CTPToolCall(id="call_1", tool="slow_tool_1", arguments={}), |
| 734 | CTPToolCall(id="call_2", tool="slow_tool_2", arguments={}), |
| 735 | ] |
| 736 | |
| 737 | results = [] |
| 738 | |
| 739 | async def consumer(): |
| 740 | async for result in stream_execute_tools(manager, calls, batch_timeout=100.0): |
| 741 | results.append(result) |
| 742 | |
| 743 | task = asyncio.create_task(consumer()) |
| 744 | # Give the generator time to start and block on queue.get() |
| 745 | await asyncio.sleep(0.05) |
| 746 | task.cancel() |
| 747 | |
| 748 | try: |
| 749 | await task |
| 750 | except asyncio.CancelledError: |
| 751 | pass # expected |
| 752 | |
| 753 | # No results should have been received (tools are too slow) |
| 754 | assert results == [] |
| 755 | |
| 756 | |
| 757 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected