def test_timeout(self): """Test the timeout.""" self.connection.node._connection_timeout = 0 muxer = Multiplexer([self.connection]) with pytest.raises(Exception): muxer.connect() muxer.disconnect()
def test_connect_twice_with_loop(): """Test that connecting twice the multiplexer behaves correctly.""" running_loop = asyncio.new_event_loop() thread_loop = Thread(target=running_loop.run_forever) thread_loop.start() try: multiplexer = Multiplexer([_make_dummy_connection()], loop=running_loop) with unittest.mock.patch.object(multiplexer.logger, "debug") as mock_logger_debug: assert not multiplexer.connection_status.is_connected multiplexer.connect() assert multiplexer.connection_status.is_connected multiplexer.connect() assert multiplexer.connection_status.is_connected mock_logger_debug.assert_called_with( "Multiplexer already connected.") multiplexer.disconnect() running_loop.call_soon_threadsafe(running_loop.stop) finally: thread_loop.join()
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.counterparty = receiver_address dummy_connection = _make_dummy_connection() multiplexer = Multiplexer([dummy_connection]) outbox = OutBox(multiplexer, agent_address) inbox = InBox(multiplexer) multiplexer.connect() envelope = Envelope( to=receiver_address, sender=agent_address, protocol_id=DefaultMessage.protocol_id, message=msg, ) outbox.put(envelope) time.sleep(0.5) assert not inbox.empty(), "Inbox must not be empty after putting an envelope" multiplexer.disconnect()
def _run_interaction_channel(): # load agent configuration file loader = ConfigLoader.from_configuration_type(PackageType.AGENT) agent_configuration = loader.load(Path(DEFAULT_AEA_CONFIG_FILE).open()) agent_name = agent_configuration.name # load stub connection configuration = ConnectionConfig( input_file=DEFAULT_OUTPUT_FILE_NAME, output_file=DEFAULT_INPUT_FILE_NAME, connection_id=StubConnection.connection_id, ) identity_stub = Identity(agent_name + "_interact", "interact") stub_connection = StubConnection(configuration=configuration, identity=identity_stub) multiplexer = Multiplexer([stub_connection]) inbox = InBox(multiplexer) outbox = OutBox(multiplexer, default_address=identity_stub.address) dialogues = DefaultDialogues(identity_stub.name) try: multiplexer.connect() while True: # pragma: no cover _process_envelopes(agent_name, identity_stub, inbox, outbox, dialogues) except KeyboardInterrupt: click.echo("Interaction interrupted!") except BaseException as e: # pylint: disable=broad-except # pragma: no cover click.echo(e) finally: multiplexer.disconnect()
def test_node_disconnect(self): """Test node disconnect.""" muxer = Multiplexer([self.connection]) muxer.connect() self.connection.node.proc.terminate() self.connection.node.proc.wait() muxer.disconnect()
def setup_class(cls): """Set the test up""" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() os.chdir(cls.t) cls.log_files = [] port_genesis = DEFAULT_PORT + 10 cls.connection_genesis = _make_libp2p_connection(port_genesis) cls.multiplexer_genesis = Multiplexer([cls.connection_genesis]) cls.log_files.append(cls.connection_genesis.node.log_file) cls.multiplexer_genesis.connect() genesis_peer = cls.connection_genesis.node.multiaddrs[0] cls.connections = [cls.connection_genesis] cls.multiplexers = [cls.multiplexer_genesis] port = port_genesis for _ in range(DEFAULT_NET_SIZE): port += 1 conn = _make_libp2p_connection(port=port, entry_peers=[genesis_peer]) muxer = Multiplexer([conn]) cls.connections.append(conn) cls.multiplexers.append(muxer) cls.log_files.append(conn.node.log_file) muxer.connect()
def test_multiplexer_connect_one_raises_error_many_connections(): """Test the case when the multiplexer raises an exception while attempting the connection of one connection.""" node = LocalNode() tmpdir = Path(tempfile.mkdtemp()) d = tmpdir / "test_stub" d.mkdir(parents=True) input_file_path = d / "input_file.csv" output_file_path = d / "input_file.csv" connection_1 = _make_local_connection("my_addr", node) connection_2 = _make_stub_connection(input_file_path, output_file_path) connection_3 = _make_dummy_connection() multiplexer = Multiplexer([connection_1, connection_2, connection_3]) assert not connection_1.connection_status.is_connected assert not connection_2.connection_status.is_connected assert not connection_3.connection_status.is_connected with unittest.mock.patch.object(connection_3, "connect", side_effect=Exception): with pytest.raises( AEAConnectionError, match="Failed to connect the multiplexer." ): multiplexer.connect() assert not connection_1.connection_status.is_connected assert not connection_2.connection_status.is_connected assert not connection_3.connection_status.is_connected multiplexer.disconnect() try: shutil.rmtree(tmpdir) except OSError as e: logger.warning("Couldn't delete {}".format(tmpdir)) logger.exception(e)
def test_send_message_no_supported_protocol(): """Test the case when we send an envelope with a specific connection that does not support the protocol.""" with LocalNode() as node: identity_1 = Identity("", address="address_1") public_id = PublicId.from_str("fetchai/my_private_protocol:0.1.0") connection_1 = _make_local_connection( identity_1.address, node, restricted_to_protocols={public_id}, excluded_protocols={public_id}, ) multiplexer = Multiplexer([connection_1]) multiplexer.connect() with mock.patch.object(aea.mail.base.logger, "warning") as mock_logger_warning: protocol_id = UNKNOWN_PROTOCOL_PUBLIC_ID envelope = Envelope( to=identity_1.address, sender=identity_1.address, protocol_id=protocol_id, message=b"some bytes", ) multiplexer.put(envelope) time.sleep(0.5) mock_logger_warning.assert_called_with( "Connection {} cannot handle protocol {}. Cannot send the envelope.".format( connection_1.connection_id, protocol_id ) ) multiplexer.disconnect()
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 _run_interaction_channel(): loader = ConfigLoader.from_configuration_type(PackageType.AGENT) agent_configuration = loader.load(Path(DEFAULT_AEA_CONFIG_FILE).open()) agent_name = agent_configuration.name identity_stub = Identity(agent_name + "_interact", "interact") _load_packages(identity_stub) # load agent configuration file from packages.fetchai.connections.stub.connection import ( # noqa: F811 # pylint: disable=import-outside-toplevel DEFAULT_INPUT_FILE_NAME, DEFAULT_OUTPUT_FILE_NAME, StubConnection, ) from packages.fetchai.protocols.default.dialogues import ( # noqa: F811 # pylint: disable=import-outside-toplevel DefaultDialogue, DefaultDialogues, ) from packages.fetchai.protocols.default.message import ( # noqa: F811 # pylint: disable=import-outside-toplevel DefaultMessage, ) # load stub connection configuration = ConnectionConfig( input_file=DEFAULT_OUTPUT_FILE_NAME, output_file=DEFAULT_INPUT_FILE_NAME, connection_id=StubConnection.connection_id, ) stub_connection = StubConnection( configuration=configuration, identity=identity_stub ) multiplexer = Multiplexer([stub_connection]) inbox = InBox(multiplexer) outbox = OutBox(multiplexer) def role_from_first_message( # pylint: disable=unused-argument message: Message, receiver_address: Address ) -> BaseDialogue.Role: """Infer the role of the agent from an incoming/outgoing first message :param message: an incoming/outgoing first message :param receiver_address: the address of the receiving agent :return: The role of the agent """ return DefaultDialogue.Role.AGENT dialogues = DefaultDialogues(identity_stub.name, role_from_first_message) try: multiplexer.connect() while True: # pragma: no cover _process_envelopes(agent_name, inbox, outbox, dialogues, DefaultMessage) except KeyboardInterrupt: click.echo("Interaction interrupted!") except BaseException as e: # pylint: disable=broad-except # pragma: no cover click.echo(e) finally: multiplexer.disconnect()
def test_connection(self): """Test that an OEF connection can be established to the OEF.""" connection = _make_oef_connection( FETCHAI_ADDRESS_ONE, oef_addr="127.0.0.1", oef_port=10000, ) multiplexer = Multiplexer([connection]) multiplexer.connect() multiplexer.disconnect()
def test_outbox_empty(): """Test thet the outbox queue is empty.""" dummy_connection = _make_dummy_connection() multiplexer = Multiplexer([dummy_connection]) multiplexer.connect() outbox = OutBox(multiplexer) assert outbox.empty(), "The outbox is not empty" multiplexer.disconnect()
def setup_class(cls): """Set the test up""" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() os.chdir(cls.t) cls.log_files = [] cls.multiplexers = [] try: port_relay_1 = DEFAULT_PORT + 10 cls.connection_relay_1 = _make_libp2p_connection(port_relay_1) cls.multiplexer_relay_1 = Multiplexer([cls.connection_relay_1]) cls.log_files.append(cls.connection_relay_1.node.log_file) cls.multiplexer_relay_1.connect() cls.multiplexers.append(cls.multiplexer_relay_1) relay_peer_1 = cls.connection_relay_1.node.multiaddrs[0] port_relay_2 = DEFAULT_PORT + 100 cls.connection_relay_2 = _make_libp2p_connection( port=port_relay_2, entry_peers=[relay_peer_1]) cls.multiplexer_relay_2 = Multiplexer([cls.connection_relay_2]) cls.log_files.append(cls.connection_relay_2.node.log_file) cls.multiplexer_relay_2.connect() cls.multiplexers.append(cls.multiplexer_relay_2) relay_peer_2 = cls.connection_relay_2.node.multiaddrs[0] cls.connections = [cls.connection_relay_1, cls.connection_relay_2] port = port_relay_1 for _ in range(int(DEFAULT_NET_SIZE / 2) + 1): port += 1 conn = _make_libp2p_connection(port=port, relay=False, entry_peers=[relay_peer_1]) mux = Multiplexer([conn]) cls.connections.append(conn) cls.log_files.append(conn.node.log_file) mux.connect() cls.multiplexers.append(mux) port = port_relay_2 for _ in range(int(DEFAULT_NET_SIZE / 2) + 1): port += 1 conn = _make_libp2p_connection(port=port, relay=False, entry_peers=[relay_peer_2]) mux = Multiplexer([conn]) cls.connections.append(conn) cls.log_files.append(conn.node.log_file) mux.connect() cls.multiplexers.append(mux) except Exception as e: cls.teardown_class() raise e
def test_disconnect_twice(): """Test that connecting twice the multiplexer behaves correctly.""" multiplexer = Multiplexer([_make_dummy_connection()]) assert not multiplexer.connection_status.is_connected multiplexer.connect() assert multiplexer.connection_status.is_connected multiplexer.disconnect() multiplexer.disconnect()
async def test_sending_loop_cancelled(): """Test the case when the sending loop is cancelled.""" multiplexer = Multiplexer([_make_dummy_connection()]) multiplexer.connect() await asyncio.sleep(0.1) with unittest.mock.patch.object(aea.mail.base.logger, "debug") as mock_logger_debug: multiplexer.disconnect() mock_logger_debug.assert_any_call("Sending loop cancelled.")
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_multiplexer_connect_all_raises_error(): """Test the case when the multiplexer raises an exception while connecting.""" multiplexer = Multiplexer([_make_dummy_connection()]) with unittest.mock.patch.object(multiplexer, "_connect_all", side_effect=Exception): with pytest.raises( AEAConnectionError, match="Failed to connect the multiplexer." ): multiplexer.connect() multiplexer.disconnect()
def test_communication_indirect(self): assert (len(PUBLIC_DHT_DELEGATE_URIS) > 1), "Test requires at least 2 public dht node" for i in range(len(PUBLIC_DHT_DELEGATE_URIS)): connection1 = _make_libp2p_client_connection( uri=PUBLIC_DHT_DELEGATE_URIS[i]) multiplexer1 = Multiplexer([connection1]) multiplexer1.connect() addr_1 = connection1.address msg = DefaultMessage( dialogue_reference=("", ""), message_id=1, target=0, performative=DefaultMessage.Performative.BYTES, content=b"hello", ) for j in range(len(PUBLIC_DHT_DELEGATE_URIS)): if j == i: continue connection2 = _make_libp2p_client_connection( uri=PUBLIC_DHT_DELEGATE_URIS[j]) multiplexer2 = Multiplexer([connection2]) multiplexer2.connect() addr_2 = connection2.address 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) try: 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) assert envelope.message == msg except Exception: multiplexer1.disconnect() raise finally: multiplexer2.disconnect() multiplexer1.disconnect()
async def test_receiving_loop_terminated(): """Test that connecting twice the multiplexer behaves correctly.""" multiplexer = Multiplexer([_make_dummy_connection()]) multiplexer.connect() with unittest.mock.patch.object(aea.mail.base.logger, "debug") as mock_logger_debug: multiplexer.connection_status.is_connected = False await multiplexer._receiving_loop() mock_logger_debug.assert_called_with("Receiving loop terminated.") multiplexer.connection_status.is_connected = True multiplexer.disconnect()
def test_multiplexer(): """Tests if the multiplexer is connected.""" with LocalNode() as node: address_1 = "address_1" oef_local_connection = _make_local_connection(address_1, node) multiplexer = Multiplexer([oef_local_connection]) multiplexer.connect() assert ( multiplexer.is_connected ), "Mailbox cannot connect to the specific Connection(OEFLocalConnection)" multiplexer.disconnect()
def test_connection(): """Test that two OEF local connection can connect to a local node.""" with LocalNode() as node: multiplexer1 = Multiplexer([_make_local_connection("multiplexer1", node)]) multiplexer2 = Multiplexer([_make_local_connection("multiplexer2", node)]) multiplexer1.connect() multiplexer2.connect() multiplexer1.disconnect() multiplexer2.disconnect()
def setup_class(cls): """Set the test up""" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() os.chdir(cls.t) cls.log_files = [] cls.multiplexers = [] try: cls.connection_node_1 = _make_libp2p_connection( port=DEFAULT_PORT + 1, delegate_port=DEFAULT_DELEGATE_PORT + 1, delegate=True, ) cls.multiplexer_node_1 = Multiplexer([cls.connection_node_1]) cls.log_files.append(cls.connection_node_1.node.log_file) cls.multiplexer_node_1.connect() cls.multiplexers.append(cls.multiplexer_node_1) entry_peer = cls.connection_node_1.node.multiaddrs[0] cls.connection_node_2 = _make_libp2p_connection( port=DEFAULT_PORT + 2, delegate_port=DEFAULT_DELEGATE_PORT + 2, entry_peers=[entry_peer], delegate=True, ) cls.multiplexer_node_2 = Multiplexer([cls.connection_node_2]) cls.log_files.append(cls.connection_node_2.node.log_file) cls.multiplexer_node_2.connect() cls.multiplexers.append(cls.multiplexer_node_2) cls.connections = [cls.connection_node_1, cls.connection_node_2] cls.addresses = [ cls.connection_node_1.address, cls.connection_node_2.address, ] for _ in range(DEFAULT_CLIENTS_PER_NODE): for port in [DEFAULT_DELEGATE_PORT + 1, DEFAULT_DELEGATE_PORT + 2]: conn = _make_libp2p_client_connection(port) mux = Multiplexer([conn]) cls.connections.append(conn) cls.addresses.append(conn.address) mux.connect() cls.multiplexers.append(mux) except Exception: cls.teardown_class() raise
def test_connectivity(self): for uri in PUBLIC_DHT_DELEGATE_URIS: connection = _make_libp2p_client_connection(uri=uri) multiplexer = Multiplexer([connection]) multiplexer.connect() try: assert (connection.is_connected is True), "Couldn't connect to public node {}".format(uri) except Exception: raise finally: multiplexer.disconnect()
def test_send_message_no_supported_protocol(): """Test the case when we send an envelope with a specific connection that does not support the protocol.""" with LocalNode() as node: identity_1 = Identity("", address="address_1") connection_1 = _make_local_connection( identity_1.address, node, restricted_to_protocols={DefaultMessage.protocol_id}, excluded_protocols={FipaMessage.protocol_id}, ) multiplexer = Multiplexer( [connection_1], protocols=[DefaultMessage, FipaMessage, UnknownProtocolMock]) multiplexer.connect() with mock.patch.object(multiplexer.logger, "warning") as mock_logger_warning: envelope = Envelope( to=identity_1.address, sender=identity_1.address, protocol_specification_id=FipaMessage. protocol_specification_id, message=b"some bytes", ) multiplexer.put(envelope) time.sleep(0.5) mock_logger_warning.assert_called_with( "Connection {} does not support protocol {}. It is explicitly excluded." .format(connection_1.connection_id, FipaMessage.protocol_id)) with mock.patch.object(multiplexer.logger, "warning") as mock_logger_warning: envelope = Envelope( to=identity_1.address, sender=identity_1.address, protocol_specification_id=UnknownProtocolMock. protocol_specification_id, message=b"some bytes", ) multiplexer.put(envelope) time.sleep(0.5) mock_logger_warning.assert_called_with( "Connection {} does not support protocol {}. The connection is restricted to protocols in {}." .format( connection_1.connection_id, UnknownProtocolMock.protocol_id, connection_1.restricted_to_protocols, )) multiplexer.disconnect()
async def test_receiving_loop_raises_exception(): """Test the case when an error occurs when a receive is started.""" connection = _make_dummy_connection() multiplexer = Multiplexer([connection]) with unittest.mock.patch("asyncio.wait", side_effect=Exception("a weird error.")): with unittest.mock.patch.object(multiplexer.logger, "error") as mock_logger_error: multiplexer.connect() time.sleep(0.1) mock_logger_error.assert_called_with( "Error in the receiving loop: a weird error.", exc_info=True) multiplexer.disconnect()
def test_connectivity(self): for maddr in PUBLIC_DHT_MADDRS: connection = _make_libp2p_connection(DEFAULT_PORT + 1, relay=False, entry_peers=[maddr]) multiplexer = Multiplexer([connection]) self.log_files.append(connection.node.log_file) multiplexer.connect() try: assert (connection.is_connected is True ), "Couldn't connect to public node {}".format(maddr) except Exception: raise finally: multiplexer.disconnect()
def setup_class(cls): """Set the test up""" cls.cwd = os.getcwd() cls.t = tempfile.mkdtemp() os.chdir(cls.t) cls.log_files = [] cls.multiplexers = [] try: port_genesis = DEFAULT_PORT + 10 temp_dir_gen = os.path.join(cls.t, "temp_dir_gen") os.mkdir(temp_dir_gen) cls.connection_genesis = _make_libp2p_connection( data_dir=temp_dir_gen, port=port_genesis) cls.multiplexer_genesis = Multiplexer( [cls.connection_genesis], protocols=[MockDefaultMessageProtocol]) cls.log_files.append(cls.connection_genesis.node.log_file) cls.multiplexer_genesis.connect() cls.multiplexers.append(cls.multiplexer_genesis) genesis_peer = cls.connection_genesis.node.multiaddrs[0] cls.connections = [cls.connection_genesis] port = port_genesis for i in range(DEFAULT_NET_SIZE): port += 1 temp_dir = os.path.join(cls.t, f"temp_dir_{i}") os.mkdir(temp_dir) conn = _make_libp2p_connection(data_dir=temp_dir, port=port, entry_peers=[genesis_peer]) mux = Multiplexer([conn], protocols=[MockDefaultMessageProtocol]) cls.connections.append(conn) cls.log_files.append(conn.node.log_file) mux.connect() cls.multiplexers.append(mux) except Exception as e: cls.teardown_class() raise e
async def test_send_envelope_with_non_registered_connection(): """Test that sending an envelope with an unregistered connection raises an exception.""" connection = _make_dummy_connection() multiplexer = Multiplexer([connection]) multiplexer.connect() envelope = Envelope( to="", sender="", protocol_id=DefaultMessage.protocol_id, message=b"", context=EnvelopeContext(connection_id=UNKNOWN_CONNECTION_PUBLIC_ID), ) with pytest.raises(AEAConnectionError, match="No connection registered with id:.*"): await multiplexer._send(envelope) multiplexer.disconnect()
def test_multiplexer_disconnect_all_raises_error(): """Test the case when the multiplexer raises an exception while disconnecting.""" multiplexer = Multiplexer([_make_dummy_connection()]) multiplexer.connect() assert multiplexer.connection_status.is_connected with unittest.mock.patch.object(multiplexer, "_disconnect_all", side_effect=Exception): with pytest.raises(AEAConnectionError, match="Failed to disconnect the multiplexer."): multiplexer.disconnect() # # do the true disconnection - for clean the test up assert multiplexer.connection_status.is_disconnecting multiplexer.disconnect() assert multiplexer.connection_status.is_disconnected