You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_worker_runtime.py 22 kB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. import asyncio
  2. import logging
  3. import os
  4. from typing import Any, List
  5. import pytest
  6. from autogen_core import (
  7. PROTOBUF_DATA_CONTENT_TYPE,
  8. AgentId,
  9. AgentType,
  10. DefaultSubscription,
  11. DefaultTopicId,
  12. MessageContext,
  13. RoutedAgent,
  14. Subscription,
  15. TopicId,
  16. TypeSubscription,
  17. default_subscription,
  18. event,
  19. try_get_known_serializers_for_type,
  20. type_subscription,
  21. )
  22. from autogen_ext.runtimes.grpc import GrpcWorkerAgentRuntime, GrpcWorkerAgentRuntimeHost
  23. from autogen_test_utils import (
  24. CascadingAgent,
  25. CascadingMessageType,
  26. ContentMessage,
  27. LoopbackAgent,
  28. LoopbackAgentWithDefaultSubscription,
  29. MessageType,
  30. NoopAgent,
  31. )
  32. from .protos.serialization_test_pb2 import ProtoMessage
  33. @pytest.mark.grpc
  34. @pytest.mark.asyncio
  35. async def test_agent_types_must_be_unique_single_worker() -> None:
  36. host_address = "localhost:50051"
  37. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  38. host.start()
  39. worker = GrpcWorkerAgentRuntime(host_address=host_address)
  40. await worker.start()
  41. await worker.register_factory(type=AgentType("name1"), agent_factory=lambda: NoopAgent(), expected_class=NoopAgent)
  42. with pytest.raises(ValueError):
  43. await worker.register_factory(
  44. type=AgentType("name1"), agent_factory=lambda: NoopAgent(), expected_class=NoopAgent
  45. )
  46. await worker.register_factory(type=AgentType("name4"), agent_factory=lambda: NoopAgent(), expected_class=NoopAgent)
  47. await worker.stop()
  48. await host.stop()
  49. @pytest.mark.grpc
  50. @pytest.mark.asyncio
  51. async def test_agent_types_must_be_unique_multiple_workers() -> None:
  52. host_address = "localhost:50052"
  53. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  54. host.start()
  55. worker1 = GrpcWorkerAgentRuntime(host_address=host_address)
  56. await worker1.start()
  57. worker2 = GrpcWorkerAgentRuntime(host_address=host_address)
  58. await worker2.start()
  59. await worker1.register_factory(type=AgentType("name1"), agent_factory=lambda: NoopAgent(), expected_class=NoopAgent)
  60. with pytest.raises(Exception, match="Agent type name1 already registered"):
  61. await worker2.register_factory(
  62. type=AgentType("name1"), agent_factory=lambda: NoopAgent(), expected_class=NoopAgent
  63. )
  64. await worker2.register_factory(type=AgentType("name4"), agent_factory=lambda: NoopAgent(), expected_class=NoopAgent)
  65. await worker1.stop()
  66. await worker2.stop()
  67. await host.stop()
  68. @pytest.mark.grpc
  69. @pytest.mark.asyncio
  70. async def test_register_receives_publish() -> None:
  71. host_address = "localhost:50053"
  72. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  73. host.start()
  74. worker1 = GrpcWorkerAgentRuntime(host_address=host_address)
  75. await worker1.start()
  76. worker1.add_message_serializer(try_get_known_serializers_for_type(MessageType))
  77. await worker1.register_factory(
  78. type=AgentType("name1"), agent_factory=lambda: LoopbackAgent(), expected_class=LoopbackAgent
  79. )
  80. await worker1.add_subscription(TypeSubscription("default", "name1"))
  81. worker2 = GrpcWorkerAgentRuntime(host_address=host_address)
  82. await worker2.start()
  83. worker2.add_message_serializer(try_get_known_serializers_for_type(MessageType))
  84. await worker2.register_factory(
  85. type=AgentType("name2"), agent_factory=lambda: LoopbackAgent(), expected_class=LoopbackAgent
  86. )
  87. await worker2.add_subscription(TypeSubscription("default", "name2"))
  88. # Publish message from worker1
  89. await worker1.publish_message(MessageType(), topic_id=TopicId("default", "default"))
  90. # Let the agent run for a bit.
  91. await asyncio.sleep(2)
  92. # Agents in default topic source should have received the message.
  93. worker1_agent = await worker1.try_get_underlying_agent_instance(AgentId("name1", "default"), LoopbackAgent)
  94. assert worker1_agent.num_calls == 1
  95. worker2_agent = await worker2.try_get_underlying_agent_instance(AgentId("name2", "default"), LoopbackAgent)
  96. assert worker2_agent.num_calls == 1
  97. # Agents in other topic source should not have received the message.
  98. worker1_agent = await worker1.try_get_underlying_agent_instance(AgentId("name1", "other"), LoopbackAgent)
  99. assert worker1_agent.num_calls == 0
  100. worker2_agent = await worker2.try_get_underlying_agent_instance(AgentId("name2", "other"), LoopbackAgent)
  101. assert worker2_agent.num_calls == 0
  102. await worker1.stop()
  103. await worker2.stop()
  104. await host.stop()
  105. @pytest.mark.grpc
  106. @pytest.mark.asyncio
  107. async def test_register_doesnt_receive_after_removing_subscription() -> None:
  108. host_address = "localhost:50053"
  109. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  110. host.start()
  111. worker1 = GrpcWorkerAgentRuntime(host_address=host_address)
  112. await worker1.start()
  113. worker1.add_message_serializer(try_get_known_serializers_for_type(MessageType))
  114. await worker1.register_factory(
  115. type=AgentType("name1"), agent_factory=lambda: LoopbackAgent(), expected_class=LoopbackAgent
  116. )
  117. sub = DefaultSubscription(agent_type="name1")
  118. await worker1.add_subscription(sub)
  119. agent_1_instance = await worker1.try_get_underlying_agent_instance(AgentId("name1", "default"), LoopbackAgent)
  120. # Publish message from worker1
  121. await worker1.publish_message(MessageType(), topic_id=DefaultTopicId())
  122. # Let the agent run for a bit.
  123. await agent_1_instance.event.wait()
  124. agent_1_instance.event.clear()
  125. # Agents in default topic source should have received the message.
  126. assert agent_1_instance.num_calls == 1
  127. await worker1.remove_subscription(sub.id)
  128. # Publish message from worker1
  129. await worker1.publish_message(MessageType(), topic_id=DefaultTopicId())
  130. # Let the agent run for a bit.
  131. await asyncio.sleep(2)
  132. # Agent should not have received the message.
  133. assert agent_1_instance.num_calls == 1
  134. await worker1.stop()
  135. await host.stop()
  136. @pytest.mark.asyncio
  137. async def test_register_receives_publish_cascade_single_worker() -> None:
  138. host_address = "localhost:50054"
  139. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  140. host.start()
  141. runtime = GrpcWorkerAgentRuntime(host_address=host_address)
  142. await runtime.start()
  143. num_agents = 5
  144. num_initial_messages = 5
  145. max_rounds = 5
  146. total_num_calls_expected = 0
  147. for i in range(0, max_rounds):
  148. total_num_calls_expected += num_initial_messages * ((num_agents - 1) ** i)
  149. # Register agents
  150. for i in range(num_agents):
  151. await CascadingAgent.register(runtime, f"name{i}", lambda: CascadingAgent(max_rounds))
  152. # Publish messages
  153. for _ in range(num_initial_messages):
  154. await runtime.publish_message(CascadingMessageType(round=1), topic_id=DefaultTopicId())
  155. # Wait for all agents to finish.
  156. await asyncio.sleep(10)
  157. # Check that each agent received the correct number of messages.
  158. for i in range(num_agents):
  159. agent = await runtime.try_get_underlying_agent_instance(AgentId(f"name{i}", "default"), CascadingAgent)
  160. assert agent.num_calls == total_num_calls_expected
  161. await runtime.stop()
  162. await host.stop()
  163. @pytest.mark.grpc
  164. @pytest.mark.skip(reason="Fix flakiness")
  165. @pytest.mark.asyncio
  166. async def test_register_receives_publish_cascade_multiple_workers() -> None:
  167. logging.basicConfig(level=logging.DEBUG)
  168. host_address = "localhost:50055"
  169. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  170. host.start()
  171. # TODO: Increasing num_initial_messages or max_round to 2 causes the test to fail.
  172. num_agents = 2
  173. num_initial_messages = 1
  174. max_rounds = 1
  175. total_num_calls_expected = 0
  176. for i in range(0, max_rounds):
  177. total_num_calls_expected += num_initial_messages * ((num_agents - 1) ** i)
  178. # Run multiple workers one for each agent.
  179. workers: List[GrpcWorkerAgentRuntime] = []
  180. # Register agents
  181. for i in range(num_agents):
  182. runtime = GrpcWorkerAgentRuntime(host_address=host_address)
  183. await runtime.start()
  184. await CascadingAgent.register(runtime, f"name{i}", lambda: CascadingAgent(max_rounds))
  185. workers.append(runtime)
  186. # Publish messages
  187. publisher = GrpcWorkerAgentRuntime(host_address=host_address)
  188. publisher.add_message_serializer(try_get_known_serializers_for_type(CascadingMessageType))
  189. await publisher.start()
  190. for _ in range(num_initial_messages):
  191. await publisher.publish_message(CascadingMessageType(round=1), topic_id=DefaultTopicId())
  192. await asyncio.sleep(20)
  193. # Check that each agent received the correct number of messages.
  194. for i in range(num_agents):
  195. agent = await workers[i].try_get_underlying_agent_instance(AgentId(f"name{i}", "default"), CascadingAgent)
  196. assert agent.num_calls == total_num_calls_expected
  197. for worker in workers:
  198. await worker.stop()
  199. await publisher.stop()
  200. await host.stop()
  201. @pytest.mark.grpc
  202. @pytest.mark.asyncio
  203. async def test_default_subscription() -> None:
  204. host_address = "localhost:50056"
  205. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  206. host.start()
  207. worker = GrpcWorkerAgentRuntime(host_address=host_address)
  208. await worker.start()
  209. publisher = GrpcWorkerAgentRuntime(host_address=host_address)
  210. publisher.add_message_serializer(try_get_known_serializers_for_type(MessageType))
  211. await publisher.start()
  212. await LoopbackAgentWithDefaultSubscription.register(worker, "name", lambda: LoopbackAgentWithDefaultSubscription())
  213. await publisher.publish_message(MessageType(), topic_id=DefaultTopicId())
  214. await asyncio.sleep(2)
  215. # Agent in default topic source should have received the message.
  216. long_running_agent = await worker.try_get_underlying_agent_instance(
  217. AgentId("name", "default"), type=LoopbackAgentWithDefaultSubscription
  218. )
  219. assert long_running_agent.num_calls == 1
  220. # Agent in other topic source should not have received the message.
  221. other_long_running_agent = await worker.try_get_underlying_agent_instance(
  222. AgentId("name", key="other"), type=LoopbackAgentWithDefaultSubscription
  223. )
  224. assert other_long_running_agent.num_calls == 0
  225. await worker.stop()
  226. await publisher.stop()
  227. await host.stop()
  228. @pytest.mark.grpc
  229. @pytest.mark.asyncio
  230. async def test_default_subscription_other_source() -> None:
  231. host_address = "localhost:50057"
  232. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  233. host.start()
  234. runtime = GrpcWorkerAgentRuntime(host_address=host_address)
  235. await runtime.start()
  236. publisher = GrpcWorkerAgentRuntime(host_address=host_address)
  237. publisher.add_message_serializer(try_get_known_serializers_for_type(MessageType))
  238. await publisher.start()
  239. await LoopbackAgentWithDefaultSubscription.register(runtime, "name", lambda: LoopbackAgentWithDefaultSubscription())
  240. await publisher.publish_message(MessageType(), topic_id=DefaultTopicId(source="other"))
  241. await asyncio.sleep(2)
  242. # Agent in default namespace should have received the message
  243. long_running_agent = await runtime.try_get_underlying_agent_instance(
  244. AgentId("name", "default"), type=LoopbackAgentWithDefaultSubscription
  245. )
  246. assert long_running_agent.num_calls == 0
  247. # Agent in other namespace should not have received the message
  248. other_long_running_agent = await runtime.try_get_underlying_agent_instance(
  249. AgentId("name", key="other"), type=LoopbackAgentWithDefaultSubscription
  250. )
  251. assert other_long_running_agent.num_calls == 1
  252. await runtime.stop()
  253. await publisher.stop()
  254. await host.stop()
  255. @pytest.mark.grpc
  256. @pytest.mark.asyncio
  257. async def test_type_subscription() -> None:
  258. host_address = "localhost:50058"
  259. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  260. host.start()
  261. worker = GrpcWorkerAgentRuntime(host_address=host_address)
  262. await worker.start()
  263. publisher = GrpcWorkerAgentRuntime(host_address=host_address)
  264. publisher.add_message_serializer(try_get_known_serializers_for_type(MessageType))
  265. await publisher.start()
  266. @type_subscription("Other")
  267. class LoopbackAgentWithSubscription(LoopbackAgent): ...
  268. await LoopbackAgentWithSubscription.register(worker, "name", lambda: LoopbackAgentWithSubscription())
  269. await publisher.publish_message(MessageType(), topic_id=TopicId(type="Other", source="default"))
  270. await asyncio.sleep(2)
  271. # Agent in default topic source should have received the message.
  272. long_running_agent = await worker.try_get_underlying_agent_instance(
  273. AgentId("name", "default"), type=LoopbackAgentWithSubscription
  274. )
  275. assert long_running_agent.num_calls == 1
  276. # Agent in other topic source should not have received the message.
  277. other_long_running_agent = await worker.try_get_underlying_agent_instance(
  278. AgentId("name", key="other"), type=LoopbackAgentWithSubscription
  279. )
  280. assert other_long_running_agent.num_calls == 0
  281. await worker.stop()
  282. await publisher.stop()
  283. await host.stop()
  284. @pytest.mark.grpc
  285. @pytest.mark.asyncio
  286. async def test_duplicate_subscription() -> None:
  287. host_address = "localhost:50059"
  288. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  289. worker1 = GrpcWorkerAgentRuntime(host_address=host_address)
  290. worker1_2 = GrpcWorkerAgentRuntime(host_address=host_address)
  291. host.start()
  292. try:
  293. await worker1.start()
  294. await NoopAgent.register(worker1, "worker1", lambda: NoopAgent())
  295. await worker1_2.start()
  296. # Note: This passes because worker1 is still running
  297. with pytest.raises(Exception, match="Agent type worker1 already registered"):
  298. await NoopAgent.register(worker1_2, "worker1", lambda: NoopAgent())
  299. # This is somehow covered in test_disconnected_agent as well as a stop will also disconnect the agent.
  300. # Will keep them both for now as we might replace the way we simulate a disconnect
  301. await worker1.stop()
  302. with pytest.raises(ValueError):
  303. await NoopAgent.register(worker1_2, "worker1", lambda: NoopAgent())
  304. except Exception as ex:
  305. raise ex
  306. finally:
  307. await worker1_2.stop()
  308. await host.stop()
  309. @pytest.mark.grpc
  310. @pytest.mark.asyncio
  311. async def test_disconnected_agent() -> None:
  312. host_address = "localhost:50060"
  313. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  314. host.start()
  315. worker1 = GrpcWorkerAgentRuntime(host_address=host_address)
  316. worker1_2 = GrpcWorkerAgentRuntime(host_address=host_address)
  317. # TODO: Implementing `get_current_subscriptions` and `get_subscribed_recipients` requires access
  318. # to some private properties. This needs to be updated once they are available publicly
  319. def get_current_subscriptions() -> List[Subscription]:
  320. return host._servicer._subscription_manager._subscriptions # type: ignore[reportPrivateUsage]
  321. async def get_subscribed_recipients() -> List[AgentId]:
  322. return await host._servicer._subscription_manager.get_subscribed_recipients(DefaultTopicId()) # type: ignore[reportPrivateUsage]
  323. try:
  324. await worker1.start()
  325. await LoopbackAgentWithDefaultSubscription.register(
  326. worker1, "worker1", lambda: LoopbackAgentWithDefaultSubscription()
  327. )
  328. subscriptions1 = get_current_subscriptions()
  329. assert len(subscriptions1) == 2
  330. recipients1 = await get_subscribed_recipients()
  331. assert AgentId(type="worker1", key="default") in recipients1
  332. first_subscription_id = subscriptions1[0].id
  333. await worker1.publish_message(ContentMessage(content="Hello!"), DefaultTopicId())
  334. # This is a simple simulation of worker disconnct
  335. if worker1._host_connection is not None: # type: ignore[reportPrivateUsage]
  336. try:
  337. await worker1._host_connection.close() # type: ignore[reportPrivateUsage]
  338. except asyncio.CancelledError:
  339. pass
  340. await asyncio.sleep(1)
  341. subscriptions2 = get_current_subscriptions()
  342. assert len(subscriptions2) == 0
  343. recipients2 = await get_subscribed_recipients()
  344. assert len(recipients2) == 0
  345. await asyncio.sleep(1)
  346. await worker1_2.start()
  347. await LoopbackAgentWithDefaultSubscription.register(
  348. worker1_2, "worker1", lambda: LoopbackAgentWithDefaultSubscription()
  349. )
  350. subscriptions3 = get_current_subscriptions()
  351. assert len(subscriptions3) == 2
  352. assert first_subscription_id not in [x.id for x in subscriptions3]
  353. recipients3 = await get_subscribed_recipients()
  354. assert len(set(recipients2)) == len(recipients2) # Make sure there are no duplicates
  355. assert AgentId(type="worker1", key="default") in recipients3
  356. except Exception as ex:
  357. raise ex
  358. finally:
  359. await worker1.stop()
  360. await worker1_2.stop()
  361. @default_subscription
  362. class ProtoReceivingAgent(RoutedAgent):
  363. def __init__(self) -> None:
  364. super().__init__("A loop back agent.")
  365. self.num_calls = 0
  366. self.received_messages: list[Any] = []
  367. @event
  368. async def on_new_message(self, message: ProtoMessage, ctx: MessageContext) -> None: # type: ignore
  369. self.num_calls += 1
  370. self.received_messages.append(message)
  371. @pytest.mark.grpc
  372. @pytest.mark.asyncio
  373. async def test_proto_payloads() -> None:
  374. host_address = "localhost:50057"
  375. host = GrpcWorkerAgentRuntimeHost(address=host_address)
  376. host.start()
  377. receiver_runtime = GrpcWorkerAgentRuntime(
  378. host_address=host_address, payload_serialization_format=PROTOBUF_DATA_CONTENT_TYPE
  379. )
  380. await receiver_runtime.start()
  381. publisher_runtime = GrpcWorkerAgentRuntime(
  382. host_address=host_address, payload_serialization_format=PROTOBUF_DATA_CONTENT_TYPE
  383. )
  384. publisher_runtime.add_message_serializer(try_get_known_serializers_for_type(ProtoMessage))
  385. await publisher_runtime.start()
  386. await ProtoReceivingAgent.register(receiver_runtime, "name", ProtoReceivingAgent)
  387. await publisher_runtime.publish_message(ProtoMessage(message="Hello!"), topic_id=DefaultTopicId())
  388. await asyncio.sleep(2)
  389. # Agent in default namespace should have received the message
  390. long_running_agent = await receiver_runtime.try_get_underlying_agent_instance(
  391. AgentId("name", "default"), type=ProtoReceivingAgent
  392. )
  393. assert long_running_agent.num_calls == 1
  394. assert long_running_agent.received_messages[0].message == "Hello!"
  395. # Agent in other namespace should not have received the message
  396. other_long_running_agent = await receiver_runtime.try_get_underlying_agent_instance(
  397. AgentId("name", key="other"), type=ProtoReceivingAgent
  398. )
  399. assert other_long_running_agent.num_calls == 0
  400. assert len(other_long_running_agent.received_messages) == 0
  401. await receiver_runtime.stop()
  402. await publisher_runtime.stop()
  403. await host.stop()
  404. # TODO add tests for failure to deserialize
  405. @pytest.mark.grpc
  406. @pytest.mark.asyncio
  407. @pytest.mark.skip(reason="Fix flakiness")
  408. async def test_grpc_max_message_size() -> None:
  409. default_max_size = 2**22
  410. new_max_size = default_max_size * 2
  411. small_message = ContentMessage(content="small message")
  412. big_message = ContentMessage(content="." * (default_max_size + 1))
  413. extra_grpc_config = [
  414. ("grpc.max_send_message_length", new_max_size),
  415. ("grpc.max_receive_message_length", new_max_size),
  416. ]
  417. host_address = "localhost:50061"
  418. host = GrpcWorkerAgentRuntimeHost(address=host_address, extra_grpc_config=extra_grpc_config)
  419. worker1 = GrpcWorkerAgentRuntime(host_address=host_address, extra_grpc_config=extra_grpc_config)
  420. worker2 = GrpcWorkerAgentRuntime(host_address=host_address)
  421. worker3 = GrpcWorkerAgentRuntime(host_address=host_address, extra_grpc_config=extra_grpc_config)
  422. try:
  423. host.start()
  424. await worker1.start()
  425. await worker2.start()
  426. await worker3.start()
  427. await LoopbackAgentWithDefaultSubscription.register(
  428. worker1, "worker1", lambda: LoopbackAgentWithDefaultSubscription()
  429. )
  430. await LoopbackAgentWithDefaultSubscription.register(
  431. worker2, "worker2", lambda: LoopbackAgentWithDefaultSubscription()
  432. )
  433. await LoopbackAgentWithDefaultSubscription.register(
  434. worker3, "worker3", lambda: LoopbackAgentWithDefaultSubscription()
  435. )
  436. # with pytest.raises(Exception):
  437. await worker1.publish_message(small_message, DefaultTopicId())
  438. # This is a simple simulation of worker disconnct
  439. await asyncio.sleep(1)
  440. agent_instance_2 = await worker2.try_get_underlying_agent_instance(
  441. AgentId("worker2", key="default"), type=LoopbackAgent
  442. )
  443. agent_instance_3 = await worker3.try_get_underlying_agent_instance(
  444. AgentId("worker3", key="default"), type=LoopbackAgent
  445. )
  446. assert agent_instance_2.num_calls == 1
  447. assert agent_instance_3.num_calls == 1
  448. await worker1.publish_message(big_message, DefaultTopicId())
  449. await asyncio.sleep(2)
  450. assert agent_instance_2.num_calls == 1 # Worker 2 won't receive the big message
  451. assert agent_instance_3.num_calls == 2 # Worker 3 will receive the big message as has increased message length
  452. except Exception as e:
  453. raise e
  454. finally:
  455. await worker1.stop()
  456. # await worker2.stop() # Worker 2 somehow breaks can can not be stopped.
  457. await worker3.stop()
  458. await host.stop()
  459. if __name__ == "__main__":
  460. os.environ["GRPC_VERBOSITY"] = "DEBUG"
  461. os.environ["GRPC_TRACE"] = "all"
  462. asyncio.run(test_disconnected_agent())
  463. asyncio.run(test_grpc_max_message_size())