diff --git a/.github/workflows/test-mango.yml b/.github/workflows/test-mango.yml index 4c60586d..1a7d6b55 100644 --- a/.github/workflows/test-mango.yml +++ b/.github/workflows/test-mango.yml @@ -13,12 +13,54 @@ permissions: contents: read jobs: - build: + build-mac: + runs-on: macOS-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: '**/setup.py' + - name: Install dependencies + run: | + pip install virtualenv + virtualenv venv + source venv/bin/activate + pip3 install -U sphinx + pip3 install -r docs/requirements.txt + pip3 install -r requirements.txt + pip3 install -e . + brew install mosquitto + brew services start mosquitto + pip3 install pytest coverage ruff + - name: Lint with ruff + run: | + # stop the build if there are Python syntax errors or undefined names + source venv/bin/activate + ruff check . + ruff format --check . + - name: Doctests + run: | + source venv/bin/activate + make -C docs doctest + - name: Test+Coverage + run: | + source venv/bin/activate + coverage run -m pytest + coverage report + + build-linux: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: Set up Python diff --git a/docs/source/agents-container.rst b/docs/source/agents-container.rst index 84adfb7a..94eea96f 100644 --- a/docs/source/agents-container.rst +++ b/docs/source/agents-container.rst @@ -28,6 +28,7 @@ a simple but fast network protocol. codec: Codec = None, clock: Clock = None, copy_internal_messages: bool = False, + auto_port=False, **kwargs: dict[str, Any], ) -> Container: @@ -41,14 +42,14 @@ A simple container, that uses plain tcp for message exchange can be created as f from mango import create_tcp_container def get_simple_container(): - container = create_tcp_container(addr=('localhost', 5555)) + container = create_tcp_container(addr=('127.0.0.1', 5555)) return container print(get_simple_container().addr) .. testoutput:: - ('localhost', 5555) + ('127.0.0.1', 5555) The container type depends totally on the factory method you invoke. Every supported type has its own class backing the functionality. @@ -66,7 +67,7 @@ asynchronous context manager, which we provide by invoking :meth:`mango.activate from mango import create_tcp_container, activate async def start_container(): - container = create_tcp_container(addr=('localhost', 5555)) + container = create_tcp_container(addr=('127.0.0.1', 5555)) async with activate(container) as c: print("The container is activated now!") @@ -105,7 +106,7 @@ Note that, custom agents that inherit from the ``Agent`` class have to call ``su pass async def create_and_register_agent(): - container = create_tcp_container(addr=('localhost', 5555)) + container = create_tcp_container(addr=('127.0.0.1', 5555)) agent = container.register(MyAgent(), suggested_aid="CustomAgent") return agent diff --git a/docs/source/codecs.rst b/docs/source/codecs.rst index 0f61f6ef..8bff901d 100644 --- a/docs/source/codecs.rst +++ b/docs/source/codecs.rst @@ -113,8 +113,8 @@ All that is left to do now is to pass our codec to the container. This is done d # codecs can be passed directly to the container # if no codec is passed a new instance of JSON() is created - sending_container = create_tcp_container(addr=("localhost", 5556), codec=codec) - receiving_container = create_tcp_container(addr=("localhost", 5555), codec=codec) + sending_container = create_tcp_container(addr=("127.0.0.1", 5556), codec=codec) + receiving_container = create_tcp_container(addr=("127.0.0.1", 5555), codec=codec) receiving_agent = receiving_container.register(SimpleReceivingAgent()) async with activate(sending_container, receiving_container): diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 6b5d8508..9b72a3f5 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -56,12 +56,12 @@ found in :doc:`Agents and container ` # Containers have to be created using a factory method # Other container types are available through create_mqtt_container and create_ec_container - container = create_tcp_container(addr=('localhost', 5555)) + container = create_tcp_container(addr=('127.0.0.1', 5555)) print(container.addr) .. testoutput:: - ('localhost', 5555) + ('127.0.0.1', 5555) This is how a tcp container is created. While container creation, it is possible to set the codec, the address information (depending on the type) @@ -103,12 +103,12 @@ The following script will create a RepeatingAgent, register it, and let it run w async with activate(first_container) as container: await asyncio.sleep(duration) - asyncio.run(run_container_and_agent(addr=('localhost', 5555), duration=0.05)) + asyncio.run(run_container_and_agent(addr=('127.0.0.1', 5555), duration=0.05)) .. testoutput:: Creating a RepeatingAgent. At this point self.addr=None - The agent has been registered to a container: AgentAddress(protocol_addr=('localhost', 5555), aid='agent0')! + The agent has been registered to a container: AgentAddress(protocol_addr=('127.0.0.1', 5555), aid='agent0')! All containers have been activated! In this example no messages are sent, nor does the Agent do anything, but the call order of the hook-in functions is clearly visible. @@ -142,7 +142,7 @@ to another agent: async with activate(first_container) as container: await first_hello_agent.greet(second_hello_agent.addr) - asyncio.run(run_container_and_agent(addr=('localhost', 5555), duration=0.05)) + asyncio.run(run_container_and_agent(addr=('127.0.0.1', 5555), duration=0.05)) .. testoutput:: @@ -198,13 +198,13 @@ a RepeatingAgent and let them run. await asyncio.sleep(.1) asyncio.run(run_container_and_two_agents( - first_addr=('localhost', 5555), second_addr=('localhost', 5556)) + first_addr=('127.0.0.1', 5555), second_addr=('127.0.0.1', 5556)) ) .. testoutput:: Creating a RepeatingAgent. At this point self.addr=None - The agent has been registered to a container: AgentAddress(protocol_addr=('localhost', 5555), aid='agent0')! + The agent has been registered to a container: AgentAddress(protocol_addr=('127.0.0.1', 5555), aid='agent0')! All containers have been activated! Received a message with the following content: Hello world!! diff --git a/docs/source/role-api.rst b/docs/source/role-api.rst index 04336b7c..82d9fbd0 100644 --- a/docs/source/role-api.rst +++ b/docs/source/role-api.rst @@ -175,8 +175,8 @@ determine the message dispatch order (lower number = earlier execution, default= async def show_handle_sub(): my_composed_agent = agent_composed_of(MyRole()) - async with run_with_tcp(1, my_composed_agent) as cl: - await cl[0].send_message(Ping(), my_composed_agent.addr) + async with run_with_tcp(1, my_composed_agent) as container: + await container.send_message(Ping(), my_composed_agent.addr) asyncio.run(show_handle_sub()) diff --git a/docs/source/scheduling.rst b/docs/source/scheduling.rst index 33f04b0c..2604874b 100644 --- a/docs/source/scheduling.rst +++ b/docs/source/scheduling.rst @@ -196,8 +196,8 @@ In the following a simple example is shown. from mango import DistributedClockAgent, DistributedClockManager, create_tcp_container, activate, ExternalClock async def main(): - container_man = create_tcp_container(("localhost", 1555), clock=ExternalClock()) - container_ag = create_tcp_container(("localhost", 1556), clock=ExternalClock()) + container_man = create_tcp_container(("127.0.0.1", 1555), clock=ExternalClock()) + container_ag = create_tcp_container(("127.0.0.1", 1556), clock=ExternalClock()) clock_agent = container_ag.register(DistributedClockAgent()) clock_manager = container_man.register(DistributedClockManager( diff --git a/docs/source/tutorial.rst b/docs/source/tutorial.rst index e3bb8f8d..a0bb4510 100644 --- a/docs/source/tutorial.rst +++ b/docs/source/tutorial.rst @@ -83,7 +83,7 @@ For this tutorial we will cover the tcp container. from mango import create_tcp_container - PV_CONTAINER_ADDRESS = ("localhost", 5555) + PV_CONTAINER_ADDRESS = ("127.0.0.1", 5555) pv_container = create_tcp_container(addr=PV_CONTAINER_ADDRESS) @@ -91,7 +91,7 @@ For this tutorial we will cover the tcp container. .. testoutput:: - ('localhost', 5555) + ('127.0.0.1', 5555) Now we can create our agents. Agents always live inside a container and therefore need to be registered to the container. @@ -110,7 +110,7 @@ Now we can create our agents. Agents always live inside a container and therefor Hello I am a PV agent! Hello I am a PV agent! - AgentAddress(protocol_addr=('localhost', 5555), aid='agent1') + AgentAddress(protocol_addr=('127.0.0.1', 5555), aid='agent1') For now, our agents and containers are purely passive entities. First, we need to activate the container to start the tcp server and its internal asynchronous behavior. In mango this can be done with :meth:`mango.activate` and the `async with` syntax. @@ -143,7 +143,7 @@ is wrapped in the :class:`mango.AgentAddress` class and can be retrieved with :m Hello I am a PV agent! Hello I am a PV agent! - Received message with content: Hello, this is a simple message. and meta {'sender_id': 'agent2', 'sender_addr': ('localhost', 5555), 'receiver_id': 'agent3', 'network_protocol': 'tcp', 'priority': 0}. + Received message with content: Hello, this is a simple message. and meta {'sender_id': 'agent2', 'sender_addr': ('127.0.0.1', 5555), 'receiver_id': 'agent3', 'network_protocol': 'tcp', 'priority': 0}. ********************************* @@ -369,8 +369,8 @@ Lastly, we call all relevant instantiations and the run function within our main from mango import create_tcp_container, activate, Performatives - PV_CONTAINER_ADDRESS = ("localhost", 5555) - CONTROLLER_CONTAINER_ADDRESS = ("localhost", 5556) + PV_CONTAINER_ADDRESS = ("127.0.0.1", 5555) + CONTROLLER_CONTAINER_ADDRESS = ("127.0.0.1", 5556) PV_FEED_IN = { 'PV Agent 0': 2.0, 'PV Agent 1': 1.0, @@ -464,8 +464,8 @@ Next, we need to create a codec, make our message objects known to it, and pass from mango import JSON - PV_CONTAINER_ADDRESS = ("localhost", 5555) - CONTROLLER_CONTAINER_ADDRESS = ("localhost", 5556) + PV_CONTAINER_ADDRESS = ("127.0.0.1", 5555) + CONTROLLER_CONTAINER_ADDRESS = ("127.0.0.1", 5556) my_codec = JSON() my_codec.add_serializer(*AskFeedInMsg.__serializer__()) @@ -675,8 +675,8 @@ also run tasks at specific times. For a full overview we refer to the documentat from mango import sender_addr, Role, RoleAgent, JSON, create_tcp_container, json_serializable, agent_composed_of - PV_CONTAINER_ADDRESS = ("localhost", 5555) - CONTROLLER_CONTAINER_ADDRESS = ("localhost", 5556) + PV_CONTAINER_ADDRESS = ("127.0.0.1", 5555) + CONTROLLER_CONTAINER_ADDRESS = ("127.0.0.1", 5556) PV_FEED_IN = { "PV Agent 0": 2.0, "PV Agent 1": 1.0, diff --git a/mango/__init__.py b/mango/__init__.py index e993dded..18808790 100644 --- a/mango/__init__.py +++ b/mango/__init__.py @@ -20,7 +20,6 @@ from .messages.codecs import ( json_serializable, JSON, - FastJSON, PROTOBUF, SerializationError, ) diff --git a/mango/container/factory.py b/mango/container/factory.py index 8b4437ed..204f4506 100644 --- a/mango/container/factory.py +++ b/mango/container/factory.py @@ -61,6 +61,7 @@ def create_tcp( codec: Codec = None, clock: Clock = None, copy_internal_messages: bool = False, + auto_port=False, **kwargs: dict[str, Any], ) -> Container: """ @@ -81,7 +82,7 @@ def create_tcp( # initialize TCPContainer return TCPContainer( - addr=addr, + addr=(addr[0], 0) if auto_port else addr, codec=codec, clock=clock, copy_internal_messages=copy_internal_messages, diff --git a/mango/container/mp.py b/mango/container/mp.py index 51861bff..35ea4623 100644 --- a/mango/container/mp.py +++ b/mango/container/mp.py @@ -2,7 +2,7 @@ import logging import os from dataclasses import dataclass -from multiprocessing import Event, Process +from multiprocessing import get_context from multiprocessing.synchronize import Event as MultiprocessingEvent import dill # noqa F401 # do not remove! Necessary for the auto loaded pickle reg extensions @@ -102,16 +102,21 @@ def create_agent_process_environment( :type process_initialized_event: Event """ asyncio.set_event_loop(asyncio.new_event_loop()) + container_data.codec = dill.loads(container_data.codec) + agent_creator = dill.loads(agent_creator) + mirror_container_creator = dill.loads(mirror_container_creator) async def start_agent_loop(): container = mirror_container_creator( container_data, asyncio.get_event_loop(), - message_pipe, + message_pipe.dup(), main_queue, - event_pipe, + event_pipe.dup(), terminate_event, ) + message_pipe.close() + event_pipe.close() if asyncio.iscoroutinefunction(agent_creator): await agent_creator(container) else: @@ -354,11 +359,12 @@ def __init__( self._active = False self._container = container self._mp_enabled = False + self._ctx = get_context("spawn") def _init_mp(self): # For agent multiprocessing support self._agent_processes = [] - self._terminate_sub_processes = Event() + self._terminate_sub_processes = self._ctx.Event() self._pid_to_message_pipe = {} self._pid_to_pipe = {} self._pid_to_aids = {} @@ -439,21 +445,21 @@ def create_agent_process(self, agent_creator, container, mirror_container_creato self._init_mp() self._active = True - from_pipe_message, to_pipe_message = aioduplex() - from_pipe, to_pipe = aioduplex() - process_initialized = Event() + from_pipe_message, to_pipe_message = aioduplex(self._ctx) + from_pipe, to_pipe = aioduplex(self._ctx) + process_initialized = self._ctx.Event() with to_pipe.detach() as to_pipe, to_pipe_message.detach() as to_pipe_message: - agent_process = Process( + agent_process = self._ctx.Process( target=create_agent_process_environment, args=( ContainerData( addr=container.addr, - codec=container.codec, + codec=dill.dumps(container.codec), clock=container.clock, kwargs=container._kwargs, ), - agent_creator, - mirror_container_creator, + dill.dumps(agent_creator), + dill.dumps(mirror_container_creator), to_pipe_message, self._main_queue, to_pipe, @@ -465,19 +471,25 @@ def create_agent_process(self, agent_creator, container, mirror_container_creato agent_process.daemon = True agent_process.start() - self._pid_to_message_pipe[agent_process.pid] = from_pipe_message - self._pid_to_pipe[agent_process.pid] = from_pipe + from_pipe_message_dup = from_pipe_message.dup() + from_pipe_dup = from_pipe.dup() + from_pipe_message.close() + from_pipe.close() + self._pid_to_message_pipe[agent_process.pid] = from_pipe_message_dup + self._pid_to_pipe[agent_process.pid] = from_pipe_dup self._handle_process_events_tasks.append( - asyncio.create_task(self._handle_process_events(from_pipe)) + asyncio.create_task(self._handle_process_events(from_pipe_dup)) ) self._handle_sp_messages_tasks.append( - asyncio.create_task(self._handle_process_message(from_pipe_message)) + asyncio.create_task(self._handle_process_message(from_pipe_message_dup)) ) async def wait_for_process_initialized(): while not process_initialized.is_set(): await asyncio.sleep(WAIT_STEP) + await asyncio.sleep(0) + return AgentProcessHandle( asyncio.create_task(wait_for_process_initialized()), agent_process.pid ) diff --git a/mango/container/tcp.py b/mango/container/tcp.py index 076024ae..3e616b5a 100644 --- a/mango/container/tcp.py +++ b/mango/container/tcp.py @@ -198,6 +198,8 @@ async def start(self): self.addr[0], self.addr[1], ) + # if 0 is specified + self.addr = (self.addr[0], self.server.sockets[0]._sock.getsockname()[1]) await super().start() async def send_message( diff --git a/mango/express/api.py b/mango/express/api.py index 5f2283f4..7be1c098 100644 --- a/mango/express/api.py +++ b/mango/express/api.py @@ -57,6 +57,8 @@ async def __aenter__(self): self.__activation_cm = activate(container_list) await self.__activation_cm.__aenter__() await self.after_start(container_list, self._agents) + if len(container_list) == 1: + return container_list[0] return container_list async def __aexit__(self, exc_type, exc, tb): @@ -70,6 +72,7 @@ def __init__( *agents: Agent | tuple[Agent, dict], addr: tuple[str, int] = ("127.0.0.1", 5555), codec: None | Codec = None, + auto_port: bool = False, ) -> None: agents = [ agent if isinstance(agent, tuple) else (agent, dict()) @@ -79,10 +82,14 @@ def __init__( self._addr = addr self._codec = codec + self.__auto_port = auto_port def create_container_list(self, num): return [ - create_tcp((self._addr[0], self._addr[1] + i), codec=self._codec) + create_tcp( + (self._addr[0], 0 if self.__auto_port else self._addr[1] + i), + codec=self._codec, + ) for i in range(num) ] @@ -157,6 +164,7 @@ def run_with_tcp( *agents: Agent | tuple[Agent, dict], addr: tuple[str, int] = ("127.0.0.1", 5555), codec: None | Codec = None, + auto_port: bool = False, ) -> RunWithTCPManager: """ Create and return an async context manager, which can be used to run the given @@ -174,10 +182,12 @@ def run_with_tcp( :type addr: tuple[str, int], optional :param codec: the codec for the containers, defaults to None :type codec: None | Codec, optional + :param auto_port: set if the port should be chosen automatically + :type auto_port: bool :return: the async context manager to run the agents with :rtype: RunWithTCPManager """ - return RunWithTCPManager(num, agents, addr=addr, codec=codec) + return RunWithTCPManager(num, agents, addr=addr, codec=codec, auto_port=auto_port) def run_with_mqtt( diff --git a/mango/messages/codecs.py b/mango/messages/codecs.py index cadc00cb..c5ae2286 100644 --- a/mango/messages/codecs.py +++ b/mango/messages/codecs.py @@ -14,8 +14,6 @@ import inspect import json -import msgspec - from mango.messages.message import ( ACLMessage, MangoMessage, @@ -181,25 +179,6 @@ def decode(self, data): return json.loads(data.decode(), object_hook=self.deserialize_obj) -class FastJSON(Codec): - def __init__(self): - super().__init__() - self.add_serializer(*ACLMessage.__json_serializer__()) - self.add_serializer(*MangoMessage.__json_serializer__()) - self.add_serializer(*enum_serializer(Performatives)) - - self.encoder = msgspec.json.Encoder(enc_hook=self.serialize_obj) - self.decoder = msgspec.json.Decoder( - dec_hook=lambda _, b: self.deserialize_obj(b), type=MangoMessage - ) - - def encode(self, data): - return self.encoder.encode(data) - - def decode(self, data): - return self.decoder.decode(data) - - class PROTOBUF(Codec): def __init__(self): super().__init__() diff --git a/mango/messages/fast_json.py b/mango/messages/fast_json.py new file mode 100644 index 00000000..03278011 --- /dev/null +++ b/mango/messages/fast_json.py @@ -0,0 +1,22 @@ +import msgspec + +from .codecs import ACLMessage, Codec, MangoMessage, Performatives, enum_serializer + + +class FastJSON(Codec): + def __init__(self): + super().__init__() + self.add_serializer(*ACLMessage.__json_serializer__()) + self.add_serializer(*MangoMessage.__json_serializer__()) + self.add_serializer(*enum_serializer(Performatives)) + + self.encoder = msgspec.json.Encoder(enc_hook=self.serialize_obj) + self.decoder = msgspec.json.Decoder( + dec_hook=lambda _, b: self.deserialize_obj(b), type=MangoMessage + ) + + def encode(self, data): + return self.encoder.encode(data) + + def decode(self, data): + return self.decoder.decode(data) diff --git a/mango/util/multiprocessing.py b/mango/util/multiprocessing.py index 4ccab97e..3153a803 100644 --- a/mango/util/multiprocessing.py +++ b/mango/util/multiprocessing.py @@ -34,22 +34,22 @@ import dill -def aiopipe() -> tuple["AioPipeReader", "AioPipeWriter"]: +def aiopipe(ctx=None) -> tuple["AioPipeReader", "AioPipeWriter"]: """Create a pair of pipe endpoints, both readable and writable (duplex). :return: Reader-, Writer-Pair """ - rx, tx = os.pipe() + rx, tx = ctx.Pipe(False) return AioPipeReader(rx), AioPipeWriter(tx) -def aioduplex() -> tuple["AioDuplex", "AioDuplex"]: +def aioduplex(ctx=None) -> tuple["AioDuplex", "AioDuplex"]: """Create a pair of pipe endpoints, both readable and writable (duplex). :return: AioDuplex-Pair """ - rxa, txa = aiopipe() - rxb, txb = aiopipe() + rxa, txa = aiopipe(ctx) + rxb, txb = aiopipe(ctx) return AioDuplex(rxa, txb), AioDuplex(rxb, txa) @@ -220,9 +220,9 @@ class AioPipeReader(AioPipeStream): event loop, to enable asynchronous reading from the pipe fd. """ - def __init__(self, fd): - super().__init__(fd) - self.connection = OwnershiplessConnection(fd, writable=False) + def __init__(self, conn): + super().__init__(conn.fileno()) + self.connection = conn async def _open(self): rx = asyncio.StreamReader(limit=2**32) @@ -238,9 +238,9 @@ class AioPipeWriter(AioPipeStream): event loop, to enable asynchronous writing to the pipe fd. """ - def __init__(self, fd): - super().__init__(fd) - self.connection = OwnershiplessConnection(fd, readable=False) + def __init__(self, conn): + super().__init__(conn.fileno()) + self.connection = conn async def _open(self): rx = asyncio.StreamReader(limit=2**32) @@ -261,6 +261,18 @@ def __init__(self, rx: AioPipeReader, tx: AioPipeWriter): self._rx = rx self._tx = tx + def dup(self): + rf = os.dup(self._rx.connection.fileno()) + wf = os.dup(self._tx.connection.fileno()) + return AioDuplex( + AioPipeReader(OwnershiplessConnection(rf)), + AioPipeWriter(OwnershiplessConnection(wf)), + ) + + def close(self): + self._rx.connection.close() + self._tx.connection.close() + @contextmanager def detach(self): with self._rx.detach(), self._tx.detach(): diff --git a/readme.md b/readme.md index 4e480990..781231d3 100644 --- a/readme.md +++ b/readme.md @@ -89,7 +89,7 @@ The container is responsible for message exchange between agents. # Containers have to be created using a factory method # Other container types are available through create_mqtt_container and create_ec_container - container = create_tcp_container(addr=('localhost', 5555)) + container = create_tcp_container(addr=('127.0.0.1', 5555)) ``` @@ -131,7 +131,7 @@ The following script will create a RepeatingAgent, register it, and let it run w async with activate(first_container) as container: await asyncio.sleep(duration) - asyncio.run(run_container_and_agent(addr=('localhost', 5555), duration=0.05)) + asyncio.run(run_container_and_agent(addr=('127.0.0.1', 5555), duration=0.05)) ``` In this example no messages are sent, nor does the Agent do anything, but the call order of the hook-in functions is clearly visible. @@ -163,7 +163,7 @@ to another agent: async with activate(first_container) as container: await first_hello_agent.greet(second_hello_agent.addr) - asyncio.run(run_container_and_agent(addr=('localhost', 5555), duration=0.05)) + asyncio.run(run_container_and_agent(addr=('127.0.0.1', 5555), duration=0.05)) ``` diff --git a/requirements.txt b/requirements.txt index 149a9ee1..48881a92 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,5 @@ toml==0.10.1 virtualenv==20.0.31 python-dateutil==2.9.0 dill==0.3.6 -msgspec==0.18.6 apipkg>=3.0.2 six>=1.16.0 diff --git a/setup.py b/setup.py index 8101744a..b17513ef 100644 --- a/setup.py +++ b/setup.py @@ -23,14 +23,12 @@ "paho-mqtt>=2.1.0", "python-dateutil>=2.9.0", "dill>=0.3.8", - "msgspec>=0.18.6", "protobuf>=5.27.2", ] # What packages are optional? -EXTRAS = { - # 'fancy feature': ['django'], -} +EXTRAS = {"fastjson": ["msgspec>=0.18.6"]} + # The rest you shouldn't have to touch too much :) # ------------------------------------------------ diff --git a/tests/integration_tests/__init__.py b/tests/integration_tests/__init__.py index 10559b81..0e64bbde 100644 --- a/tests/integration_tests/__init__.py +++ b/tests/integration_tests/__init__.py @@ -3,7 +3,7 @@ def create_test_container(type, init_addr, repl_addr, codec): - broker = ("localhost", 1883, 60) + broker = ("127.0.0.1", 1883, 60) clock_man = ExternalClock(5) if type == "tcp": diff --git a/tests/integration_tests/test_distributed_clock.py b/tests/integration_tests/test_distributed_clock.py index 82d42b9c..a4a9938c 100644 --- a/tests/integration_tests/test_distributed_clock.py +++ b/tests/integration_tests/test_distributed_clock.py @@ -10,8 +10,8 @@ async def setup_and_run_test_case(connection_type, codec): - init_addr = ("localhost", 1555) if connection_type == "tcp" else "c1" - repl_addr = ("localhost", 1556) if connection_type == "tcp" else "c2" + init_addr = ("127.0.0.1", 1555) if connection_type == "tcp" else "c1" + repl_addr = ("127.0.0.1", 1556) if connection_type == "tcp" else "c2" container_man, container_ag = create_test_container( connection_type, init_addr, repl_addr, codec diff --git a/tests/integration_tests/test_message_roundtrip.py b/tests/integration_tests/test_message_roundtrip.py index b2854764..c63bc453 100644 --- a/tests/integration_tests/test_message_roundtrip.py +++ b/tests/integration_tests/test_message_roundtrip.py @@ -4,7 +4,7 @@ from mango import activate, addr from mango.agent.core import Agent -from mango.messages.codecs import JSON, PROTOBUF, FastJSON +from mango.messages.codecs import JSON, PROTOBUF from ..unit_tests.messages.msg_pb2 import MyMsg from . import create_test_container @@ -31,15 +31,14 @@ def string_serializer(): JSON_CODEC = JSON() -FAST_JSON_CODEC = FastJSON() PROTO_CODEC = PROTOBUF() PROTO_CODEC.add_serializer(*string_serializer()) async def setup_and_run_test_case(connection_type, codec): comm_topic = "test_topic" - init_addr = ("localhost", 1555) if connection_type == "tcp" else None - repl_addr = ("localhost", 1556) if connection_type == "tcp" else None + init_addr = ("127.0.0.1", 1555) if connection_type == "tcp" else None + repl_addr = ("127.0.0.1", 1556) if connection_type == "tcp" else None container_1, container_2 = create_test_container( connection_type, init_addr, repl_addr, codec @@ -142,6 +141,7 @@ async def test_tcp_proto(): await setup_and_run_test_case("tcp", PROTO_CODEC) +""" @pytest.mark.asyncio async def test_tcp_fast_json(): await setup_and_run_test_case("tcp", FAST_JSON_CODEC) @@ -151,6 +151,7 @@ async def test_tcp_fast_json(): @pytest.mark.mqtt async def test_mqtt_fast_json(): await setup_and_run_test_case("mqtt", FAST_JSON_CODEC) +""" @pytest.mark.asyncio diff --git a/tests/integration_tests/test_message_roundtrip_mp.py b/tests/integration_tests/test_message_roundtrip_mp.py index fc0153ed..9125d5b7 100644 --- a/tests/integration_tests/test_message_roundtrip_mp.py +++ b/tests/integration_tests/test_message_roundtrip_mp.py @@ -24,8 +24,8 @@ def handle_message(self, content, meta): @pytest.mark.asyncio async def test_mp_simple_ping_pong_multi_container_tcp(): - init_addr = ("localhost", 1555) - repl_addr = ("localhost", 1556) + init_addr = ("127.0.0.1", 1555) + repl_addr = ("127.0.0.1", 1556) aid1 = "c1_p1_agent" aid2 = "c2_p1_agent" diff --git a/tests/integration_tests/test_single_container_termination.py b/tests/integration_tests/test_single_container_termination.py index 55368492..a3c6bf4d 100644 --- a/tests/integration_tests/test_single_container_termination.py +++ b/tests/integration_tests/test_single_container_termination.py @@ -90,8 +90,8 @@ async def test_termination_single_container(): async def distribute_ping_pong_test(connection_type, codec=None, max_count=100): - init_addr = ("localhost", 1555) if connection_type == "tcp" else "c1" - repl_addr = ("localhost", 1556) if connection_type == "tcp" else "c2" + init_addr = ("127.0.0.1", 1555) if connection_type == "tcp" else "c1" + repl_addr = ("127.0.0.1", 1556) if connection_type == "tcp" else "c2" container_man, container_ag = create_test_container( connection_type, init_addr, repl_addr, codec @@ -125,8 +125,8 @@ async def distribute_ping_pong_test(connection_type, codec=None, max_count=100): async def distribute_ping_pong_test_timestamp( connection_type, codec=None, max_count=10 ): - init_addr = ("localhost", 1555) if connection_type == "tcp" else "c1" - repl_addr = ("localhost", 1556) if connection_type == "tcp" else "c2" + init_addr = ("127.0.0.1", 1555) if connection_type == "tcp" else "c1" + repl_addr = ("127.0.0.1", 1556) if connection_type == "tcp" else "c2" container_man, container_ag = create_test_container( connection_type, init_addr, repl_addr, codec @@ -191,8 +191,8 @@ async def test_distribute_ping_pong_ts_mqtt(): async def distribute_time_test_case(connection_type, codec=None): - init_addr = ("localhost", 1555) if connection_type == "tcp" else "c1" - repl_addr = ("localhost", 1556) if connection_type == "tcp" else "c2" + init_addr = ("127.0.0.1", 1555) if connection_type == "tcp" else "c1" + repl_addr = ("127.0.0.1", 1556) if connection_type == "tcp" else "c2" container_man, container_ag = create_test_container( connection_type, init_addr, repl_addr, codec @@ -240,8 +240,8 @@ async def distribute_time_test_case(connection_type, codec=None): async def send_current_time_test_case(connection_type, codec=None): - init_addr = ("localhost", 1555) if connection_type == "tcp" else "c1" - repl_addr = ("localhost", 1556) if connection_type == "tcp" else "c2" + init_addr = ("127.0.0.1", 1555) if connection_type == "tcp" else "c1" + repl_addr = ("127.0.0.1", 1556) if connection_type == "tcp" else "c2" container_man, container_ag = create_test_container( connection_type, init_addr, repl_addr, codec @@ -276,6 +276,7 @@ async def send_current_time_test_case(connection_type, codec=None): next_event = await clock_manager.get_next_event() assert receiver.scheduler.clock.time == 10 # now the response should be received + await asyncio.sleep(0.1) assert caller.i == 1, "received one message" container_man.clock.set_time(15) await clock_manager.send_current_time() diff --git a/tests/unit_tests/clock/test_external_clock.py b/tests/unit_tests/clock/test_external_clock.py index 2f389e79..a274bd10 100644 --- a/tests/unit_tests/clock/test_external_clock.py +++ b/tests/unit_tests/clock/test_external_clock.py @@ -50,7 +50,13 @@ async def track_time(start_time): await asyncio.sleep(0.1) clock.set_time(1000) results = await asyncio.gather(first_task, second_task) - assert round(results[0], 1) == 0.2 and round(results[1], 1) == 0.4 + assert round(results[0], 1) == 0.2 + assert round(results[1], 1) == 0.4 + + +def assert_os_close(va, bound, tol=0.1): + assert va >= bound + assert va <= bound + tol @pytest.mark.asyncio @@ -89,10 +95,10 @@ async def test_schedule_timestamp_task(): sim_time = int(simulation_time) + 1 else: sim_time = simulation_time - assert round(sim_time / 10, 1) == round(real_time, 1) + assert_os_close(real_time, sim_time / 10) for simulation_time, real_time in results_dict_asyncio.items(): - assert round(simulation_time, 1) == round(real_time, 1) + assert_os_close(real_time, simulation_time) @pytest.mark.asyncio @@ -152,10 +158,9 @@ def create_condition_func(num): await increase_time_task - print(results_dict) for i in range(n_tasks): - assert round(results_dict[f"external_{i}"], 1) == 1.2 - assert round(results_dict[f"asyncio_{i}"], 1) == round(0.1 + i / 10, 1) + assert_os_close(results_dict[f"external_{i}"], 1.2) + assert_os_close(results_dict[f"asyncio_{i}"], 0.1 + i / 10) @pytest.mark.asyncio @@ -197,7 +202,7 @@ async def example_periodic_coro_external(): pass for i in range(10): - assert round(results_dict["asyncio"][i], 1) == round(0.1 * i, 1) + assert_os_close(results_dict["asyncio"][i], round(0.1 * i, 1)) assert len(results_dict["external"]) == 2 for i, duration in enumerate(results_dict["external"]): - assert round(duration, 1) == i * 0.4 + assert_os_close(duration, i * 0.4) diff --git a/tests/unit_tests/container/test_mp.py b/tests/unit_tests/container/test_mp.py index 1ab00f01..ad8f5eb2 100644 --- a/tests/unit_tests/container/test_mp.py +++ b/tests/unit_tests/container/test_mp.py @@ -61,7 +61,7 @@ def handle_message(self, content, meta): ) async def test_agent_processes_ping_pong(num_sp_agents, num_sp): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 15589), copy_internal_messages=False) + c = create_tcp_container(addr=("127.0.0.1", 15589), copy_internal_messages=False) for i in range(num_sp): await c.as_agent_process( agent_creator=lambda container: [ @@ -88,7 +88,7 @@ async def test_agent_processes_ping_pong(num_sp_agents, num_sp): @pytest.mark.asyncio async def test_agent_processes_ping_pong_p_to_p(): # GIVEN - addr = ("127.0.0.2", 5829) + addr = ("127.0.0.1", 5829) aid_main_agent = "main_agent" c = create_tcp_container(addr=addr, copy_internal_messages=False) await c.as_agent_process( @@ -119,16 +119,18 @@ def agent_init(c): @pytest.mark.asyncio async def test_async_agent_processes_ping_pong_p_to_p(): # GIVEN - addr = ("127.0.0.2", 5811) + addr = ("127.0.0.1", 5811) aid_main_agent = "main_agent" c = create_tcp_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=main_agent.addr) + await p2pta.send_message(content="pong", receiver_addr=target_addr) async with activate(c) as c: await c.as_agent_process(agent_creator=agent_creator) diff --git a/tests/unit_tests/container/test_tcp.py b/tests/unit_tests/container/test_tcp.py index 6ff0c123..c3f60f2b 100644 --- a/tests/unit_tests/container/test_tcp.py +++ b/tests/unit_tests/container/test_tcp.py @@ -9,19 +9,19 @@ @pytest.mark.asyncio async def test_connection_open_close(): - c = create_tcp_container(addr=("127.0.0.2", 5555), copy_internal_messages=False) + c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=False) await c.start() await c.shutdown() @pytest.mark.asyncio async def test_connection_pool_obtain_release(): - c = create_tcp_container(addr=("127.0.0.2", 5555), copy_internal_messages=False) - c2 = create_tcp_container(addr=("127.0.0.2", 5556), copy_internal_messages=False) + c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=False) + c2 = create_tcp_container(addr=("127.0.0.1", 5556), copy_internal_messages=False) await c.start() await c2.start() - addr = "127.0.0.2", 5556 + addr = "127.0.0.1", 5556 connection_pool = TCPConnectionPool() raw_prot = ContainerProtocol(container=c, codec=c.codec) protocol = await connection_pool.obtain_connection(addr[0], addr[1], raw_prot) @@ -41,12 +41,12 @@ async def test_connection_pool_obtain_release(): @pytest.mark.asyncio async def test_connection_pool_double_obtain_release(): - c = create_tcp_container(addr=("127.0.0.2", 5555), copy_internal_messages=False) - c2 = create_tcp_container(addr=("127.0.0.2", 5556), copy_internal_messages=False) + c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=False) + c2 = create_tcp_container(addr=("127.0.0.1", 5556), copy_internal_messages=False) await c.start() await c2.start() - addr = "127.0.0.2", 5556 + addr = "127.0.0.1", 5556 connection_pool = TCPConnectionPool() raw_prot = ContainerProtocol(container=c, codec=c.codec) protocol = await connection_pool.obtain_connection(addr[0], addr[1], raw_prot) @@ -77,9 +77,9 @@ async def test_connection_pool_double_obtain_release(): @pytest.mark.asyncio async def test_ttl(): - addr = "127.0.0.2", 5556 - addr2 = "127.0.0.2", 5557 - c = create_tcp_container(addr=("127.0.0.2", 5555), copy_internal_messages=False) + addr = "127.0.0.1", 5556 + addr2 = "127.0.0.1", 5557 + c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=False) c2 = create_tcp_container(addr=addr, copy_internal_messages=False) c3 = create_tcp_container(addr=addr2, copy_internal_messages=False) await c.start() @@ -120,12 +120,12 @@ async def test_ttl(): @pytest.mark.asyncio async def test_max_connections(): - c = create_tcp_container(addr=("127.0.0.2", 5555), copy_internal_messages=False) - c2 = create_tcp_container(addr=("127.0.0.2", 5556), copy_internal_messages=False) + c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=False) + c2 = create_tcp_container(addr=("127.0.0.1", 5556), copy_internal_messages=False) await c.start() await c2.start() - addr = "127.0.0.2", 5556 + addr = "127.0.0.1", 5556 connection_pool = TCPConnectionPool(max_connections_per_target=1) raw_prot = ContainerProtocol(container=c, codec=c.codec) protocol = await connection_pool.obtain_connection(addr[0], addr[1], raw_prot) diff --git a/tests/unit_tests/core/test_agent.py b/tests/unit_tests/core/test_agent.py index 49d57fa2..42edfbc2 100644 --- a/tests/unit_tests/core/test_agent.py +++ b/tests/unit_tests/core/test_agent.py @@ -17,7 +17,7 @@ def handle_message(self, content, meta: dict[str, Any]): @pytest.mark.asyncio async def test_periodic_facade(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(MyAgent()) l = [] @@ -39,7 +39,7 @@ async def increase_counter(): @pytest.mark.asyncio async def test_send_message(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(MyAgent()) agent2 = c.register(MyAgent()) @@ -56,7 +56,7 @@ async def test_send_message(): @pytest.mark.asyncio async def test_send_acl_message(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(MyAgent()) agent2 = c.register(MyAgent()) @@ -76,7 +76,7 @@ async def test_send_acl_message(): @pytest.mark.asyncio async def test_schedule_message(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(MyAgent()) agent2 = c.register(MyAgent()) @@ -90,7 +90,7 @@ async def test_schedule_message(): @pytest.mark.asyncio async def test_schedule_acl_message(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(MyAgent()) agent2 = c.register(MyAgent()) diff --git a/tests/unit_tests/core/test_container.py b/tests/unit_tests/core/test_container.py index eb54f1ec..3464718d 100644 --- a/tests/unit_tests/core/test_container.py +++ b/tests/unit_tests/core/test_container.py @@ -1,6 +1,6 @@ import pytest -from mango import create_acl, create_tcp_container +from mango import activate, create_acl, create_tcp_container from mango.agent.core import Agent @@ -15,7 +15,7 @@ def _do_register(self, container, aid): @pytest.mark.asyncio async def test_register_aid_pattern_match(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = LooksLikeAgent() suggested_aid = "agent12" @@ -30,7 +30,7 @@ async def test_register_aid_pattern_match(): @pytest.mark.asyncio async def test_register_aid_success(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = LooksLikeAgent() suggested_aid = "cagent12" @@ -45,7 +45,7 @@ async def test_register_aid_success(): @pytest.mark.asyncio async def test_register_no_suggested(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = LooksLikeAgent() # WHEN @@ -59,7 +59,7 @@ async def test_register_no_suggested(): @pytest.mark.asyncio async def test_register_pattern_half_match(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = LooksLikeAgent() suggested_aid = "agentABC" @@ -74,7 +74,7 @@ async def test_register_pattern_half_match(): @pytest.mark.asyncio async def test_register_existing(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = LooksLikeAgent() agent2 = LooksLikeAgent() suggested_aid = "agentABC" @@ -92,7 +92,7 @@ async def test_register_existing(): @pytest.mark.asyncio async def test_is_aid_available(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) aid_to_check = "agentABC" # WHEN @@ -106,7 +106,7 @@ async def test_is_aid_available(): @pytest.mark.asyncio async def test_is_aid_available_but_match(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) aid_to_check = "agent5" # WHEN @@ -120,7 +120,7 @@ async def test_is_aid_available_but_match(): @pytest.mark.asyncio async def test_is_aid_not_available(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) c.register(LooksLikeAgent(), "abc") aid_to_check = "abc" @@ -135,7 +135,7 @@ async def test_is_aid_not_available(): @pytest.mark.asyncio async def test_is_aid_not_available_and_match(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) c.register(LooksLikeAgent()) aid_to_check = "agent0" @@ -149,7 +149,7 @@ async def test_is_aid_not_available_and_match(): @pytest.mark.asyncio async def test_create_acl_no_modify(): - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) common_acl_q = {} actual_acl_message = create_acl( "", @@ -168,7 +168,7 @@ async def test_create_acl_no_modify(): @pytest.mark.asyncio async def test_create_acl_anon(): - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) actual_acl_message = create_acl( "", receiver_addr="", receiver_id="", is_anonymous_acl=True, sender_addr=c.addr ) @@ -179,7 +179,7 @@ async def test_create_acl_anon(): @pytest.mark.asyncio async def test_create_acl_not_anon(): - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) actual_acl_message = create_acl( "", receiver_addr="", receiver_id="", is_anonymous_acl=False, sender_addr=c.addr ) @@ -199,7 +199,7 @@ class Data: @pytest.mark.asyncio async def test_send_message_no_copy(): - c = create_tcp_container(addr=("127.0.0.2", 5555), copy_internal_messages=False) + c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=False) agent1 = c.register(ExampleAgent()) message_to_send = Data() @@ -211,7 +211,7 @@ async def test_send_message_no_copy(): @pytest.mark.asyncio async def test_send_message_copy(): - c = create_tcp_container(addr=("127.0.0.2", 5555), copy_internal_messages=True) + c = create_tcp_container(addr=("127.0.0.1", 5555), copy_internal_messages=True) agent1 = c.register(ExampleAgent()) message_to_send = Data() @@ -223,7 +223,7 @@ async def test_send_message_copy(): @pytest.mark.asyncio async def test_create_acl_diff_receiver(): - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) with pytest.warns(UserWarning) as record: actual_acl_message = create_acl( "", @@ -242,10 +242,20 @@ async def test_create_acl_diff_receiver(): @pytest.mark.asyncio async def test_containers_dont_share_default_codec(): - c1 = create_tcp_container(addr=("127.0.0.2", 5555)) - c2 = create_tcp_container(addr=("127.0.0.2", 5556)) + c1 = create_tcp_container(addr=("127.0.0.1", 5555)) + c2 = create_tcp_container(addr=("127.0.0.1", 5556)) assert c1.codec is not c2.codec await c1.shutdown() await c2.shutdown() + + +@pytest.mark.asyncio +async def test_auto_port_container(): + c1 = create_tcp_container(addr=("127.0.0.1", None), auto_port=True) + + async with activate(c1): + pass + + assert c1.addr[1] is not None diff --git a/tests/unit_tests/express/test_api.py b/tests/unit_tests/express/test_api.py index da6f2feb..144357f2 100644 --- a/tests/unit_tests/express/test_api.py +++ b/tests/unit_tests/express/test_api.py @@ -57,7 +57,7 @@ def handle_message(self, content, meta: dict[str, Any]): @pytest.mark.asyncio async def test_activate_api_style_agent(): # GIVEN - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(MyAgent()) agent2 = c.register(MyAgent()) @@ -83,6 +83,25 @@ async def test_run_api_style_agent(): assert run_agent2.test_counter == 1 +@pytest.mark.asyncio +async def test_run_api_style_agent_auto_port(): + # GIVEN + run_agent = MyAgent() + run_agent2 = MyAgent() + + # WHEN + async with run_with_tcp( + 2, run_agent, run_agent2, auto_port=True, addr=("127.0.0.1", None) + ) as cl: + await run_agent.schedule_instant_message("", receiver_addr=run_agent2.addr) + await asyncio.sleep(0.1) + assert cl[0].addr[1] is not None + assert cl[1].addr[1] is not None + + # THEN + assert run_agent2.test_counter == 1 + + @pytest.mark.asyncio async def test_run_api_style_agent_with_aid(): # GIVEN diff --git a/tests/unit_tests/messages/test_codecs.py b/tests/unit_tests/messages/test_codecs.py index 6c918874..e222d49c 100644 --- a/tests/unit_tests/messages/test_codecs.py +++ b/tests/unit_tests/messages/test_codecs.py @@ -153,7 +153,7 @@ def test_codec_known(codec): # known == (Performatives, ACLMessage) msg = ACLMessage( performative=Performatives.inform, - sender_addr="localhost:1883", + sender_addr="127.0.0.1:1883", ) my_codec = codec() diff --git a/tests/unit_tests/role_agent_test.py b/tests/unit_tests/role_agent_test.py index cc46dee1..3fde9bc3 100644 --- a/tests/unit_tests/role_agent_test.py +++ b/tests/unit_tests/role_agent_test.py @@ -123,7 +123,7 @@ async def test_send_ping_pong(num_agents, num_containers): # create containers containers = [] for i in range(num_containers): - c = create_tcp_container(addr=("127.0.0.2", 5555 + i)) + c = create_tcp_container(addr=("127.0.0.1", 5555 + i)) containers.append(c) # create agents @@ -160,7 +160,7 @@ async def test_send_ping_pong_deactivated_pong(num_agents, num_containers): # create containers containers = [] for i in range(num_containers): - c = create_tcp_container(addr=("127.0.0.2", 5555 + i)) + c = create_tcp_container(addr=("127.0.0.1", 5555 + i)) containers.append(c) # create agents @@ -195,7 +195,7 @@ async def test_send_ping_pong_deactivated_pong(num_agents, num_containers): @pytest.mark.asyncio async def test_role_add_remove(): - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(RoleAgent()) role = SampleRole() agent.add_role(role) @@ -209,7 +209,7 @@ async def test_role_add_remove(): @pytest.mark.asyncio async def test_role_add_remove_context(): - c = create_tcp_container(addr=("127.0.0.2", 5555)) + c = create_tcp_container(addr=("127.0.0.1", 5555)) agent = c.register(RoleAgent()) role = SampleRole() agent.add_role(role) diff --git a/tests/unit_tests/test_agents.py b/tests/unit_tests/test_agents.py index 94f0c97a..8ee5dfe3 100644 --- a/tests/unit_tests/test_agents.py +++ b/tests/unit_tests/test_agents.py @@ -87,7 +87,7 @@ async def test_send_ping_pong(num_agents, num_containers): # create containers containers = [] for i in range(num_containers): - c = create_tcp_container(addr=("127.0.0.2", 5555 + i)) + c = create_tcp_container(addr=("127.0.0.1", 5555 + i)) containers.append(c) # create agents