Skip to content

Commit

Permalink
test multiprocessing for external coupling as well
Browse files Browse the repository at this point in the history
  • Loading branch information
maurerle committed Oct 31, 2024
1 parent 4553fc1 commit 9cf064a
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion tests/unit_tests/container/test_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

import pytest

from mango import Agent, AgentAddress, activate, addr, create_tcp_container, sender_addr
from mango import (
Agent,
AgentAddress,
activate,
addr,
create_ec_container,
create_tcp_container,
sender_addr,
)


class MyAgent(Agent):
Expand Down Expand Up @@ -157,6 +165,41 @@ def agent_init(c):
assert main_agent.test_counter == 2


@pytest.mark.asyncio
async def test_async_agent_processes_ping_pong_p_to_p_external():
# GIVEN
addr = ("127.0.0.1", 5811)
aid_main_agent = "main_agent"
c = create_ec_container(addr=addr, copy_internal_messages=False)
main_agent = c.register(P2PMainAgent(), suggested_aid=aid_main_agent)

target_addr = main_agent.addr

async def agent_creator(container):
p2pta = container.register(
P2PTestAgent(aid_main_agent), suggested_aid="process_agent1"
)
await p2pta.send_message(content="pong", receiver_addr=target_addr)

async with activate(c) as c:
c.as_agent_process(agent_creator=agent_creator)

# WHEN
def agent_init(c):
agent = c.register(MyAgent(), suggested_aid="process_agent2")
agent.schedule_instant_message(
"Message To Process Agent", AgentAddress(addr, "process_agent1")
)
return agent

c.as_agent_process(agent_creator=agent_init)

while main_agent.test_counter != 2:
await asyncio.sleep(0.01)

assert main_agent.test_counter == 2


def test_sync_setup_agent_processes():
# GIVEN
c = create_tcp_container(addr=("127.0.0.1", 15589), copy_internal_messages=False)
Expand Down

0 comments on commit 9cf064a

Please sign in to comment.