def send_unsupported_protocol(self, envelope: Envelope) -> None: """ Handle the received envelope in case the protocol is not supported. :param envelope: the envelope :return: None """ self.context.logger.warning( "Unsupported protocol: {}. You might want to add a handler for this protocol." .format(envelope.protocol_specification_id)) encoded_protocol_specification_id = base64.b85encode( str.encode(str(envelope.protocol_specification_id))) encoded_envelope = base64.b85encode(envelope.encode()) reply = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.ERROR, error_code=DefaultMessage.ErrorCode.UNSUPPORTED_PROTOCOL, error_msg="Unsupported protocol.", error_data={ "protocol_id": encoded_protocol_specification_id, "envelope": encoded_envelope, }, ) reply.sender = self.context.agent_address reply.to = envelope.sender self.context.outbox.put_message(message=reply)
def test_communication_client_server(self): """Test that envelopes can be sent from a client to a server.""" msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) expected_envelope = Envelope( to=self.server_addr, sender=self.client_addr_1, message=msg, ) self.client_1_multiplexer.put(expected_envelope) actual_envelope = self.server_multiplexer.get(block=True, timeout=5.0) assert expected_envelope.to == actual_envelope.to assert expected_envelope.sender == actual_envelope.sender assert (expected_envelope.protocol_specification_id == actual_envelope.protocol_specification_id) assert expected_envelope.message != actual_envelope.message msg = DefaultMessage.serializer.decode(actual_envelope.message) msg.to = actual_envelope.to msg.sender = actual_envelope.sender assert expected_envelope.message == msg
def handle(self, message: Message) -> None: """Handle incoming message.""" self.count += 1 if message.dialogue_reference[0] != "": rtt_ts, latency_ts = struct.unpack("dd", message.content) # type: ignore if message.dialogue_reference[0] == self.context.agent_address: self.rtt_total_time += time.time() - rtt_ts self.rtt_count += 1 self.latency_total_time += time.time() - latency_ts self.latency_count += 1 if message.dialogue_reference[0] in ["", self.context.agent_address]: # create new response_msg = DefaultMessage( dialogue_reference=(self.context.agent_address, ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=struct.pack("dd", time.time(), time.time()), ) else: # update ttfb copy rtt response_msg = DefaultMessage( dialogue_reference=message.dialogue_reference, message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=struct.pack("dd", rtt_ts, time.time()), # type: ignore ) self.context.outbox.put( make_envelope(message.to, message.sender, response_msg))
def test_envelope_initialisation(): """Testing the envelope initialisation.""" agent_address = "Agent0" receiver_address = "Agent1" msg = DefaultMessage(performative=DefaultMessage.Performative.BYTES, content="hello") msg.to = receiver_address envelope = Envelope( to=receiver_address, sender=agent_address, message=msg, ) assert envelope, "Cannot generate a new envelope" envelope.to = "ChangedAgent" envelope.sender = "ChangedSender" envelope.message = b"HelloWorld" assert envelope.to == "ChangedAgent", "Cannot set to value on Envelope" assert envelope.sender == "ChangedSender", "Cannot set sender value on Envelope" assert envelope.message == b"HelloWorld", "Cannot set message on Envelope" assert envelope.context.uri_raw is not None assert not envelope.is_sender_public_id assert not envelope.is_to_public_id
def test_reception_a(self): """Test that the connection receives what has been enqueued in the input file.""" msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) expected_envelope = Envelope( to="any", sender="anys", message=msg, ) with open(self.input_file_path, "ab+") as f: write_envelope(expected_envelope, f) actual_envelope = self.multiplexer.get(block=True, timeout=3.0) assert expected_envelope.to == actual_envelope.to assert expected_envelope.sender == actual_envelope.sender assert (expected_envelope.protocol_specification_id == actual_envelope.protocol_specification_id) msg = DefaultMessage.serializer.decode(actual_envelope.message) msg.to = actual_envelope.to msg.sender = actual_envelope.sender assert expected_envelope.message == msg
def test_no_handlers_registered(): """Test no handlers are registered for message processing.""" agent_name = "MyAgent" builder = AEABuilder() private_key_path = os.path.join(CUR_PATH, "data", DEFAULT_PRIVATE_KEY_FILE) builder.set_name(agent_name) builder.add_private_key(DEFAULT_LEDGER, private_key_path) aea = builder.build() with patch.object(aea._get_error_handler().context._logger, "warning") as mock_logger: msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) msg.to = aea.identity.address envelope = Envelope( to=aea.identity.address, sender=aea.identity.address, protocol_id=DefaultMessage.protocol_id, message=msg, ) with patch.object(aea.filter, "get_active_handlers", return_value=[]), patch.object( aea.runtime.multiplexer, "put", ): aea.handle_envelope(envelope) mock_logger.assert_any_call( f"Cannot handle envelope: no active handler registered for the protocol_id='{DefaultMessage.protocol_id}'." )
def test_error_handler_is_not_set(): """Test stop on no error handler presents.""" agent_name = "my_agent" private_key_path = os.path.join(CUR_PATH, "data", DEFAULT_PRIVATE_KEY_FILE) wallet = Wallet({DEFAULT_LEDGER: private_key_path}) identity = Identity(agent_name, address=wallet.addresses[DEFAULT_LEDGER]) resources = Resources() context_namespace = {"key1": 1, "key2": 2} agent = AEA(identity, wallet, resources, **context_namespace) msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) msg.to = agent.identity.address envelope = Envelope( to=agent.identity.address, sender=agent.identity.address, protocol_id=DefaultMessage.protocol_id, message=msg, ) with pytest.raises(_StopRuntime): agent.handle_envelope(envelope)
def test_envelope_routed(self): """Test envelope routed.""" addr_1 = self.connection1.node.address addr_2 = self.connection2.node.address msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) envelope = Envelope( to=addr_2, sender=addr_1, protocol_id=DefaultMessage.protocol_id, message=msg, ) self.multiplexer1.put(envelope) delivered_envelope = self.multiplexer2.get(block=True, timeout=20) assert delivered_envelope is not None assert delivered_envelope.to == envelope.to assert delivered_envelope.sender == envelope.sender assert delivered_envelope.protocol_id == envelope.protocol_id assert delivered_envelope.message != envelope.message msg = DefaultMessage.serializer.decode(delivered_envelope.message) msg.to = delivered_envelope.to msg.sender = delivered_envelope.sender assert envelope.message == msg
def test_outbox_put(): """Tests that an envelope is putted into the queue.""" agent_address = "Agent0" receiver_address = "Agent1" msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) msg.to = receiver_address msg.sender = agent_address dummy_connection = _make_dummy_connection() multiplexer = Multiplexer([dummy_connection]) outbox = OutBox(multiplexer) inbox = InBox(multiplexer) multiplexer.connect() envelope = Envelope( to=receiver_address, sender=agent_address, message=msg, ) outbox.put(envelope) wait_for_condition(lambda: inbox.empty(), 15, "Inbox must not be empty after putting an envelope") multiplexer.disconnect()
def send_unsupported_skill(self, envelope: Envelope) -> None: """ Handle the received envelope in case the skill is not supported. :param envelope: the envelope :return: None """ if envelope.skill_id is None: self.context.logger.warning( "Cannot handle envelope: no active handler registered for the protocol_specification_id='{}'." .format(envelope.protocol_specification_id)) else: self.context.logger.warning( "Cannot handle envelope: no active handler registered for the protocol_specification_id='{}' and skill_id='{}'." .format(envelope.protocol_specification_id, envelope.skill_id)) encoded_envelope = base64.b85encode(envelope.encode()) reply = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.ERROR, error_code=DefaultMessage.ErrorCode.UNSUPPORTED_SKILL, error_msg="Unsupported skill.", error_data={"envelope": encoded_envelope}, ) reply.sender = self.context.agent_address reply.to = envelope.sender self.context.outbox.put_message(message=reply)
def test_communication_direct(self): """Test communication direct (i.e. both clients registered to same peer).""" for i in range(len(PUBLIC_DHT_DELEGATE_URIS)): uri = PUBLIC_DHT_DELEGATE_URIS[i] peer_public_key = PUBLIC_DHT_PUBLIC_KEYS[i] multiplexers = [] try: temp_dir_1 = os.path.join(self.t, f"dir_{i}_1") os.mkdir(temp_dir_1) connection1 = _make_libp2p_client_connection( peer_public_key=peer_public_key, uri=uri, data_dir=temp_dir_1 ) multiplexer1 = Multiplexer([connection1]) multiplexer1.connect() multiplexers.append(multiplexer1) temp_dir_2 = os.path.join(self.t, f"dir_{i}_2") os.mkdir(temp_dir_2) connection2 = _make_libp2p_client_connection( peer_public_key=peer_public_key, uri=uri, data_dir=temp_dir_2 ) multiplexer2 = Multiplexer([connection2]) multiplexer2.connect() multiplexers.append(multiplexer2) addr_1 = connection1.address addr_2 = connection2.address msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) envelope = Envelope(to=addr_2, sender=addr_1, message=msg,) multiplexer1.put(envelope) delivered_envelope = multiplexer2.get(block=True, timeout=20) assert delivered_envelope is not None assert delivered_envelope.to == envelope.to assert delivered_envelope.sender == envelope.sender assert ( delivered_envelope.protocol_specification_id == envelope.protocol_specification_id ) assert delivered_envelope.message != envelope.message msg = DefaultMessage.serializer.decode(delivered_envelope.message) msg.to = delivered_envelope.to msg.sender = delivered_envelope.sender assert envelope.message == msg except Exception: raise finally: for mux in multiplexers: mux.disconnect()
def test_communication_direct(self): """Test communication direct.""" for maddr in PUBLIC_DHT_MADDRS: multiplexers = [] try: connection1 = _make_libp2p_connection(DEFAULT_PORT + 1, relay=False, entry_peers=[maddr]) multiplexer1 = Multiplexer([connection1]) self.log_files.append(connection1.node.log_file) multiplexer1.connect() multiplexers.append(multiplexer1) connection2 = _make_libp2p_connection(DEFAULT_PORT + 2, relay=False, entry_peers=[maddr]) multiplexer2 = Multiplexer([connection2]) self.log_files.append(connection2.node.log_file) multiplexer2.connect() multiplexers.append(multiplexer2) addr_1 = connection1.node.address addr_2 = connection2.node.address msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) envelope = Envelope( to=addr_2, sender=addr_1, protocol_id=DefaultMessage.protocol_id, message=msg, ) multiplexer1.put(envelope) delivered_envelope = multiplexer2.get(block=True, timeout=20) assert delivered_envelope is not None assert delivered_envelope.to == envelope.to assert delivered_envelope.sender == envelope.sender assert delivered_envelope.protocol_id == envelope.protocol_id assert delivered_envelope.message != envelope.message msg = DefaultMessage.serializer.decode( delivered_envelope.message) msg.to = delivered_envelope.to msg.sender = delivered_envelope.sender assert envelope.message == msg except Exception: raise finally: for mux in multiplexers: mux.disconnect()
def test_get_quantity_in_outbox(self): """Test the get_quantity_in_outbox method.""" assert self.get_quantity_in_outbox() == 0 dummy_message = DefaultMessage( performative=DefaultMessage.Performative.BYTES, content="dummy") dummy_message.to = "some_to" dummy_message.sender = "some_sender" self.skill.skill_context.outbox.put_message(dummy_message) assert self.get_quantity_in_outbox() == 1
async def test_outbox_negative(): """Test InBox OutBox objects.""" connection_1 = _make_dummy_connection() connections = [connection_1] multiplexer = AsyncMultiplexer(connections, loop=asyncio.get_event_loop()) msg = DefaultMessage( performative=DefaultMessage.Performative.BYTES, content=b"", ) context = EnvelopeContext(connection_id=connection_1.connection_id) envelope = Envelope( to="to", sender="sender", protocol_specification_id=msg.protocol_specification_id, message=b"", context=context, ) try: await multiplexer.connect() outbox = OutBox(multiplexer) assert outbox.empty() with pytest.raises(ValueError) as execinfo: outbox.put(envelope) assert ( str(execinfo.value) == "Only Message type allowed in envelope message field when putting into outbox." ) assert outbox.empty() with pytest.raises(ValueError) as execinfo: outbox.put_message("") assert str(execinfo.value) == "Provided message not of type Message." assert outbox.empty() with pytest.raises(ValueError) as execinfo: outbox.put_message(msg) assert str( execinfo.value) == "Provided message has message.to not set." assert outbox.empty() msg.to = "to" with pytest.raises(ValueError) as execinfo: outbox.put_message(msg) assert str( execinfo.value) == "Provided message has message.sender not set." finally: await multiplexer.disconnect()
def test_react(): """Tests income messages.""" with LocalNode() as node: agent_name = "MyAgent" private_key_path = os.path.join(CUR_PATH, "data", DEFAULT_PRIVATE_KEY_FILE) builder = AEABuilder() builder.set_name(agent_name) builder.add_private_key(DEFAULT_LEDGER, private_key_path) builder.add_protocol( Path(ROOT_DIR, "packages", "fetchai", "protocols", "oef_search")) builder.add_connection( Path(ROOT_DIR, "packages", "fetchai", "connections", "local")) local_connection_id = OEFLocalConnection.connection_id builder.set_default_connection(local_connection_id) builder.add_skill(Path(CUR_PATH, "data", "dummy_skill")) agent = builder.build(connection_ids=[local_connection_id]) # This is a temporary workaround to feed the local node to the OEF Local connection # TODO remove it. local_connection = agent.resources.get_connection(local_connection_id) local_connection._local_node = node msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) msg.to = agent.identity.address msg.sender = agent.identity.address envelope = Envelope( to=msg.to, sender=msg.sender, protocol_id=msg.protocol_id, message=msg, ) with run_in_thread(agent.start, timeout=20, on_exit=agent.stop): wait_for_condition(lambda: agent.is_running, timeout=20) agent.outbox.put(envelope) default_protocol_public_id = DefaultMessage.protocol_id dummy_skill_public_id = DUMMY_SKILL_PUBLIC_ID handler = agent.resources.get_handler(default_protocol_public_id, dummy_skill_public_id) assert handler is not None, "Handler is not set." wait_for_condition( lambda: len(handler.handled_messages) > 0, timeout=20, error_msg="The message is not inside the handled_messages.", )
def test_envelope_message_bytes(): """Test the property Envelope.message_bytes.""" message = DefaultMessage(DefaultMessage.Performative.BYTES, content=b"message") envelope = Envelope( to="to", sender="sender", message=message, ) expected_message_bytes = message.encode() actual_message_bytes = envelope.message_bytes assert expected_message_bytes == actual_message_bytes
def test_envelope_message_bytes(): """Test the property Envelope.message_bytes.""" message = DefaultMessage(DefaultMessage.Performative.BYTES, content=b"message") envelope = Envelope( to="to", sender="sender", protocol_id=PublicId("author", "name", "0.1.0"), message=message, ) expected_message_bytes = message.encode() actual_message_bytes = envelope.message_bytes assert expected_message_bytes == actual_message_bytes
def test_check_consistency_raises_exception_when_type_not_recognized(): """Test that we raise exception when the type of the message is not recognized.""" message = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) # mock the __eq__ method such that any kind of matching is going to fail. with mock.patch.object(DefaultMessage.Performative, "__eq__", return_value=False): assert not message._is_consistent()
def make_test_envelope(to_="any", sender_="sender") -> Envelope: """Create a test envelope.""" msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) msg.to = to_ msg.sender = sender_ envelope = Envelope( to=to_, sender=sender_, protocol_id=DefaultMessage.protocol_id, message=msg, ) return envelope
def on_dialogue_error( # pylint: disable=unused-argument self, answer_id: int, dialogue_id: int, origin: Address) -> None: """ On dialogue error event handler. :param answer_id: the answer id. :param dialogue_id: the dialogue id. :param origin: the message sender. :return: None """ self._check_loop_and_queue() msg = DefaultMessage( performative=DefaultMessage.Performative.ERROR, dialogue_reference=(str(answer_id), ""), target=TARGET, message_id=MESSAGE_ID, error_code=DefaultMessage.ErrorCode.INVALID_DIALOGUE, error_msg="Destination not available", error_data={}, ) envelope = Envelope( to=self.address, sender=DEFAULT_OEF, message=msg, ) asyncio.run_coroutine_threadsafe(self.in_queue.put(envelope), self.loop)
def test_envelope_echoed_back(self): """Test envelope echoed back.""" addr_1 = self.connection1.node.address addr_2 = self.connection2.node.address msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) original_envelope = Envelope( to=addr_2, sender=addr_1, protocol_id=DefaultMessage.protocol_id, message=msg, ) self.multiplexer1.put(original_envelope) delivered_envelope = self.multiplexer2.get(block=True, timeout=10) assert delivered_envelope is not None delivered_envelope.to = addr_1 delivered_envelope.sender = addr_2 self.multiplexer2.put(delivered_envelope) echoed_envelope = self.multiplexer1.get(block=True, timeout=5) assert echoed_envelope is not None assert echoed_envelope.to == original_envelope.sender assert delivered_envelope.sender == original_envelope.to assert delivered_envelope.protocol_id == original_envelope.protocol_id assert delivered_envelope.message != original_envelope.message assert original_envelope.message_bytes == delivered_envelope.message_bytes
async def test_connection_twice_return_none(): """Test that connecting twice works.""" with LocalNode() as node: address = "address" connection = _make_local_connection(address, node) await connection.connect() await node.connect(address, connection._reader) message = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) expected_envelope = Envelope( to=address, sender=address, protocol_id=DefaultMessage.protocol_id, message=message, ) await connection.send(expected_envelope) actual_envelope = await connection.receive() assert expected_envelope == actual_envelope await connection.disconnect()
def test_assert_quantity_in_outbox(self): """Test the assert_quantity_in_outbox method.""" with pytest.raises( AssertionError, match= f"Invalid number of messages in outbox. Expected {1}. Found {0}.", ): self.assert_quantity_in_outbox(1) dummy_message = DefaultMessage( performative=DefaultMessage.Performative.BYTES, content="dummy") dummy_message.to = "some_to" dummy_message.sender = "some_sender" self.skill.skill_context.outbox.put_message(dummy_message) self.assert_quantity_in_outbox(1)
def test_star_routing_connectivity(self): """Test routing with star connectivity.""" msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) for source in range(len(self.multiplexers)): for destination in range(len(self.multiplexers)): if destination == source: continue envelope = Envelope( to=self.addresses[destination], sender=self.addresses[source], protocol_id=DefaultMessage.protocol_id, message=DefaultSerializer().encode(msg), ) self.multiplexers[source].put(envelope) delivered_envelope = self.multiplexers[destination].get( block=True, timeout=10 ) assert delivered_envelope is not None assert delivered_envelope.to == envelope.to assert delivered_envelope.sender == envelope.sender assert delivered_envelope.protocol_id == envelope.protocol_id assert delivered_envelope.message == envelope.message
def test_envelope_routed(self): """Test the envelope is routed.""" addr_1 = self.connection_client_1.address addr_2 = self.connection_client_2.address msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) envelope = Envelope( to=addr_2, sender=addr_1, protocol_id=DefaultMessage.protocol_id, message=DefaultSerializer().encode(msg), ) self.multiplexer_client_1.put(envelope) delivered_envelope = self.multiplexer_client_2.get(block=True, timeout=20) assert delivered_envelope is not None assert delivered_envelope.to == envelope.to assert delivered_envelope.sender == envelope.sender assert delivered_envelope.protocol_id == envelope.protocol_id assert delivered_envelope.message == envelope.message
def test_connection_is_established(self): """Test the stub connection is established and then bad formatted messages.""" assert self.connection.is_connected msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) encoded_envelope = "{}{}{}{}{}{}{}{}".format( "any", SEPARATOR, "any", SEPARATOR, DefaultMessage.protocol_specification_id, SEPARATOR, DefaultMessage.serializer.encode(msg).decode("utf-8"), SEPARATOR, ) encoded_envelope = base64.b64encode(encoded_envelope.encode("utf-8")) envelope = envelope_from_bytes(encoded_envelope) if envelope is not None: self.connection._put_envelopes([envelope]) assert (self.connection.in_queue.empty() ), "The inbox must be empty due to bad encoded message"
async def _handle_agent_message(self, envelope: Envelope) -> None: """ Forward an envelope to the right agent. :param envelope: the envelope :return: None """ destination = envelope.to if destination not in self._out_queues.keys(): msg = DefaultMessage( performative=DefaultMessage.Performative.ERROR, dialogue_reference=("", ""), target=TARGET, message_id=MESSAGE_ID, error_code=DefaultMessage.ErrorCode.INVALID_DIALOGUE, error_msg="Destination not available", error_data={}, ) error_envelope = Envelope( to=envelope.sender, sender=str(OEFLocalConnection.connection_id), protocol_id=DefaultMessage.protocol_id, message=msg, ) await self._send(error_envelope) return await self._send(envelope)
def dummy_default_message( cls, dialogue_reference: Tuple[str, str] = ("", ""), message_id: int = 1, target: int = 0, performative: DefaultMessage.Performative = DefaultMessage. Performative.BYTES, content: Union[str, bytes] = "hello world!", ) -> Message: """ Construct simple message, all arguments are optional. :param dialogue_reference: the dialogue reference. :param message_id: the message id. :param target: the message target. :param performative: the message performative. :param content: string or bytes payload. :return: Message """ if isinstance(content, str): content = content.encode("utf-8") return DefaultMessage( dialogue_reference=dialogue_reference, message_id=message_id, target=target, performative=performative, content=content, )
def test_envelope_echoed_back_node_agent(self): """Test the envelope is echoed back node agent.""" addr_1 = self.connection_client_1.address addr_n = self.connection_node_2.address msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) original_envelope = Envelope( to=addr_n, sender=addr_1, protocol_id=DefaultMessage.protocol_id, message=DefaultSerializer().encode(msg), ) self.multiplexer_client_1.put(original_envelope) delivered_envelope = self.multiplexer_node_2.get(block=True, timeout=10) assert delivered_envelope is not None delivered_envelope.to = addr_1 delivered_envelope.sender = addr_n self.multiplexer_node_2.put(delivered_envelope) echoed_envelope = self.multiplexer_client_1.get(block=True, timeout=5) assert echoed_envelope is not None assert echoed_envelope.to == original_envelope.sender assert delivered_envelope.sender == original_envelope.to assert delivered_envelope.protocol_id == original_envelope.protocol_id assert delivered_envelope.message == original_envelope.message
def test_assert_quantity_in_decision_making_queue(self): """Test the assert_quantity_in_decision_making_queue method.""" with pytest.raises( AssertionError, match= f"Invalid number of messages in decision maker queue. Expected {1}. Found {0}.", ): self.assert_quantity_in_decision_making_queue(1) dummy_message = DefaultMessage( performative=DefaultMessage.Performative.BYTES, content="dummy_1") dummy_message.to = "some_to_1" dummy_message.sender = "some_sender_1" self.skill.skill_context.decision_maker_message_queue.put( dummy_message) self.assert_quantity_in_decision_making_queue(1)