|
3 | 3 | from autogen_core.base import AgentId, TopicId
|
4 | 4 | from autogen_core.base.exceptions import CantHandleException
|
5 | 5 | from autogen_core.components import DefaultTopicId, TypeSubscription
|
| 6 | +from autogen_core.components import DefaultSubscription |
6 | 7 | from test_utils import LoopbackAgent, MessageType
|
7 | 8 |
|
8 | 9 |
|
@@ -96,3 +97,22 @@ async def test_skipped_class_subscriptions() -> None:
|
96 | 97 | AgentId("MyAgent", key="default"), type=LoopbackAgent
|
97 | 98 | )
|
98 | 99 | assert agent_instance.num_calls == 0
|
| 100 | + |
| 101 | + |
| 102 | +@pytest.mark.asyncio |
| 103 | +async def test_subscription_deduplication() -> None: |
| 104 | + runtime = SingleThreadedAgentRuntime() |
| 105 | + agent_type = "MyAgent" |
| 106 | + |
| 107 | + # Test TypeSubscription |
| 108 | + type_subscription_1 = TypeSubscription("default", agent_type) |
| 109 | + type_subscription_2 = TypeSubscription("default", agent_type) |
| 110 | + |
| 111 | + await runtime.add_subscription(type_subscription_1) |
| 112 | + with pytest.raises(ValueError, match="Subscription already exists"): |
| 113 | + await runtime.add_subscription(type_subscription_2) |
| 114 | + |
| 115 | + # Test DefaultSubscription |
| 116 | + default_subscription = DefaultSubscription(agent_type=agent_type) |
| 117 | + with pytest.raises(ValueError, match="Subscription already exists"): |
| 118 | + await runtime.add_subscription(default_subscription) |
0 commit comments