Test max_concurrency limits parallel execution.
()
| 181 | |
| 182 | @pytest.mark.asyncio |
| 183 | async def test_execute_tools_parallel_max_concurrency(): |
| 184 | """Test max_concurrency limits parallel execution.""" |
| 185 | execution_count = 0 |
| 186 | max_concurrent = 0 |
| 187 | |
| 188 | original_execute = MockToolManager.execute_tool |
| 189 | |
| 190 | async def tracking_execute( |
| 191 | self, tool_name, arguments, namespace=None, timeout=None |
| 192 | ): |
| 193 | nonlocal execution_count, max_concurrent |
| 194 | execution_count += 1 |
| 195 | current = execution_count |
| 196 | max_concurrent = max(max_concurrent, current) |
| 197 | await asyncio.sleep(0.01) # Simulate work |
| 198 | execution_count -= 1 |
| 199 | return await original_execute(self, tool_name, arguments, namespace, timeout) |
| 200 | |
| 201 | manager = MockToolManager() |
| 202 | manager.execute_tool = lambda *args, **kwargs: tracking_execute( |
| 203 | manager, *args, **kwargs |
| 204 | ) |
| 205 | |
| 206 | calls = [ |
| 207 | CTPToolCall(id=f"call_{i}", tool=f"tool_{i}", arguments={}) for i in range(10) |
| 208 | ] |
| 209 | |
| 210 | await execute_tools_parallel(manager, calls, max_concurrency=2) |
| 211 | |
| 212 | # Max concurrent should not exceed 2 (though timing may vary) |
| 213 | assert max_concurrent <= 3 # Allow some slack due to async timing |
| 214 | |
| 215 | |
| 216 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected