MCPcopy Create free account
hub / github.com/IBM/mcp-cli / test_stream_execute_tools_max_concurrency

Function test_stream_execute_tools_max_concurrency

tests/tools/test_execution.py:462–495  ·  view source on GitHub ↗

Test stream_execute_tools respects max_concurrency.

()

Source from the content-addressed store, hash-verified

460
461@pytest.mark.asyncio
462async def test_stream_execute_tools_max_concurrency():
463 """Test stream_execute_tools respects max_concurrency."""
464 execution_count = 0
465 max_concurrent = 0
466
467 original_execute = MockToolManager.execute_tool
468
469 async def tracking_execute(
470 self, tool_name, arguments, namespace=None, timeout=None
471 ):
472 nonlocal execution_count, max_concurrent
473 execution_count += 1
474 current = execution_count
475 max_concurrent = max(max_concurrent, current)
476 await asyncio.sleep(0.01) # Simulate work
477 execution_count -= 1
478 return await original_execute(self, tool_name, arguments, namespace, timeout)
479
480 manager = MockToolManager()
481 manager.execute_tool = lambda *args, **kwargs: tracking_execute(
482 manager, *args, **kwargs
483 )
484
485 calls = [
486 CTPToolCall(id=f"call_{i}", tool=f"tool_{i}", arguments={}) for i in range(5)
487 ]
488
489 results = []
490 async for result in stream_execute_tools(manager, calls, max_concurrency=2):
491 results.append(result)
492
493 assert len(results) == 5
494 # Max concurrent should not exceed 2 (with some slack for async timing)
495 assert max_concurrent <= 3
496
497
498# ----------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 3

stream_execute_toolsFunction · 0.90
tracking_executeFunction · 0.85
MockToolManagerClass · 0.70

Tested by

no test coverage detected