Skip to content

Commit

Permalink
Merge pull request #125 from maurerle/raise_double_register
Browse files Browse the repository at this point in the history
raise exception when trying to register a container which is already registered
  • Loading branch information
rcschrg authored Oct 28, 2024
2 parents 5a557d9 + a0ede0f commit 39abc5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mango/container/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def register(self, agent: Agent, suggested_aid: str = None):
:return The agent ID
"""
aid = self._reserve_aid(suggested_aid)
if agent.context:
raise ValueError("Agent is already registered to a container")
self._agents[aid] = agent
agent._do_register(self, aid)
logger.debug("Successfully registered agent;%s", aid)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit_tests/core/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ async def test_schedule_acl_message():
# THEN
assert agent2.test_counter == 1

def test_register_twice():
c = create_tcp_container(addr=("127.0.0.1", 5555))
agent = MyAgent()
c.register(agent)

with pytest.raises(ValueError):
c.register(agent)

def test_sync_setup_agent():
# this test is not async and therefore does not provide a running event loop
Expand Down

0 comments on commit 39abc5a

Please sign in to comment.