Skip to content

Commit 697fd43

Browse files
committed
Merge master into fix/docstring-parser-drops-params
2 parents f8afb78 + 96eb15f commit 697fd43

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

tests/structs/test_agent_rearrange.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77

88
from swarms import Agent, AgentRearrange
9+
from swarms.telemetry.otel import ContextThreadPoolExecutor
910

1011

1112
def create_sample_agents():
@@ -611,7 +612,9 @@ def bad_run(*args, **kwargs):
611612
raise TypeError("unexpected error in agent")
612613

613614
next(
614-
agent for agent in r.agents if agent.agent_name == "WriterAgent"
615+
agent
616+
for agent in r.agents
617+
if agent.agent_name == "WriterAgent"
615618
).run = bad_run
616619

617620
with pytest.raises(TypeError, match="unexpected error in agent"):
@@ -1018,29 +1021,25 @@ def instrumented_run(task, img=None, *a, **kw):
10181021
), "Expected at least two batch_run tasks to overlap in execution"
10191022

10201023
def test_threadpoolexecutor_is_used(self):
1021-
"""Patch ThreadPoolExecutor to confirm it is invoked for each batch."""
1024+
"""Patch the executor to confirm it is invoked for each batch."""
10221025
pipeline = _make_pipeline("AgentA", "AgentB")
10231026
tasks = ["t1", "t2", "t3"]
10241027

10251028
with patch(
1026-
"swarms.structs.agent_rearrange.ThreadPoolExecutor",
1027-
wraps=__import__(
1028-
"concurrent.futures", fromlist=["ThreadPoolExecutor"]
1029-
).ThreadPoolExecutor,
1029+
"swarms.structs.agent_rearrange.ContextThreadPoolExecutor",
1030+
wraps=ContextThreadPoolExecutor,
10301031
) as mock_tpe:
10311032
pipeline.batch_run(tasks=tasks, batch_size=10)
10321033
assert mock_tpe.call_count == 1
10331034

10341035
def test_multiple_batches_uses_executor_per_batch(self):
1035-
"""One ThreadPoolExecutor context-manager per batch."""
1036+
"""One executor context-manager per batch."""
10361037
pipeline = _make_pipeline("AgentA", "AgentB")
10371038
tasks = [f"t{i}" for i in range(6)]
10381039

10391040
with patch(
1040-
"swarms.structs.agent_rearrange.ThreadPoolExecutor",
1041-
wraps=__import__(
1042-
"concurrent.futures", fromlist=["ThreadPoolExecutor"]
1043-
).ThreadPoolExecutor,
1041+
"swarms.structs.agent_rearrange.ContextThreadPoolExecutor",
1042+
wraps=ContextThreadPoolExecutor,
10441043
) as mock_tpe:
10451044
pipeline.batch_run(tasks=tasks, batch_size=2)
10461045
# 6 tasks / batch_size=2 -> 3 batches -> 3 executor instances
@@ -1204,13 +1203,11 @@ def test_various_batch_sizes_return_all_results(self, batch_size):
12041203
assert len(results) == len(tasks)
12051204

12061205
def test_batch_size_one_still_uses_executor(self):
1207-
"""Even batch_size=1 should go through ThreadPoolExecutor."""
1206+
"""Even batch_size=1 should go through the executor."""
12081207
pipeline = _make_pipeline("AgentA", "AgentB")
12091208
with patch(
1210-
"swarms.structs.agent_rearrange.ThreadPoolExecutor",
1211-
wraps=__import__(
1212-
"concurrent.futures", fromlist=["ThreadPoolExecutor"]
1213-
).ThreadPoolExecutor,
1209+
"swarms.structs.agent_rearrange.ContextThreadPoolExecutor",
1210+
wraps=ContextThreadPoolExecutor,
12141211
) as mock_tpe:
12151212
pipeline.batch_run(tasks=["only"], batch_size=1)
12161213
assert mock_tpe.call_count == 1

0 commit comments

Comments
 (0)