Skip to content

Commit

Permalink
the context of the role context was not initialized. This should dele…
Browse files Browse the repository at this point in the history
…gate to the _agent_context

A setter is generally not needed for this, except for the initialization where it is set to None
  • Loading branch information
maurerle committed Oct 21, 2024
1 parent a599f28 commit 04fde2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mango/agent/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ def data(self):
:rtype: DataContainer
"""
return self._get_container()

@property
def context(self) -> float:
return self._agent_context

@context.setter
def context(self, value: bool):
pass

@property
def current_timestamp(self) -> float:
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_tests/express/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,23 @@ async def test_activate_pingpong():
await c.send_message(
"Ping", ping_pong_agent.addr, sender_id=ping_pong_agent_two.aid
)
assert ping_pong_agent.roles[0].context.addr is not None
while ping_pong_agent.roles[0].counter < 5:
await asyncio.sleep(0.01)

assert ping_pong_agent.roles[0].counter == 5


@pytest.mark.asyncio
async def test_activate_rolecontext():
container = create_tcp_container("127.0.0.1:5555")
ping_pong_agent = agent_composed_of(PingPongRole(), register_in=container)

async with activate(container) as c:
assert ping_pong_agent.roles[0].context.addr is not None
assert ping_pong_agent.roles[0].context.context is not None


class MyAgent(Agent):
test_counter: int = 0

Expand Down

0 comments on commit 04fde2d

Please sign in to comment.