Skip to content

Commit

Permalink
Merge pull request #137 from OFFIS-DAI/fix-internal-messaging
Browse files Browse the repository at this point in the history
Fixing parsing of host:port string.
  • Loading branch information
rcschrg authored Nov 9, 2024
2 parents 9fae986 + f7e7ff4 commit ed859ce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mango/container/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def create_tcp(
if clock is None:
clock = AsyncioClock()
if isinstance(addr, str):
addr = tuple(addr.split(":"))
host, port = addr.split(":")
addr = (host, int(port))

# initialize TCPContainer
return TCPContainer(
Expand Down
28 changes: 26 additions & 2 deletions tests/unit_tests/core/test_container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from dataclasses import dataclass

import pytest

from mango import activate, create_acl, create_tcp_container
Expand Down Expand Up @@ -220,12 +222,34 @@ async def test_send_message_no_copy():
async def test_send_message_copy():
c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=True)
agent1 = c.register(ExampleAgent())
agent2 = c.register(ExampleAgent())

message_to_send = Data()

async with activate(c):
await c.send_message(message_to_send, receiver_addr=agent1.addr)
await agent1.send_message(message_to_send, agent2.addr)

assert agent2.content is not message_to_send


@dataclass
class DataCompl:
i = 0


@pytest.mark.asyncio
async def test_send_message_internal_cls():
c = create_tcp_container(addr="localhost:5555")
agent1 = c.register(ExampleAgent())
agent2 = c.register(ExampleAgent())

message_to_send = DataCompl()
addr = agent2.addr

async with activate(c):
await c.send_message(message_to_send, addr)

assert agent1.content is not message_to_send
assert agent2.content is message_to_send


@pytest.mark.asyncio
Expand Down

0 comments on commit ed859ce

Please sign in to comment.