Esempio n. 1
0
def test_join_global_room():
    """ join_global_room should try joining, fail and then create global public room """
    ownserver = 'https://ownserver.com'
    api = Mock()
    api.base_url = ownserver

    client = Mock()
    client.api = api

    def create_room(alias, is_public=False, invitees=None):
        room = Room(client, f'!room_id:ownserver.com')
        room.canonical_alias = alias
        return room

    client.create_room = Mock(side_effect=create_room)
    client.join_room = Mock(side_effect=MatrixRequestError(404))

    room_name = 'raiden_ropsten_discovery'

    room = join_global_room(
        client=client,
        name=room_name,
        servers=['https://invalid.server'],
    )
    assert client.join_room.call_count == 2  # room not found on own and invalid servers
    client.create_room.assert_called_once_with(
        room_name, is_public=True)  # created successfuly
    assert room and isinstance(room, Room)
Esempio n. 2
0
    def setup_matrix(self, service_room_suffix: str) -> Tuple[GMatrixClient, Room]:
        available_servers_url = DEFAULT_MATRIX_KNOWN_SERVERS[Environment.DEVELOPMENT]
        available_servers = get_matrix_servers(available_servers_url)

        def _http_retry_delay() -> Iterable[float]:
            # below constants are defined in raiden.app.App.DEFAULT_CONFIG
            return udp_utils.timeout_exponential_backoff(
                DEFAULT_TRANSPORT_RETRIES_BEFORE_BACKOFF,
                int(DEFAULT_TRANSPORT_MATRIX_RETRY_INTERVAL / 5),
                int(DEFAULT_TRANSPORT_MATRIX_RETRY_INTERVAL),
            )

        client = make_client(
            servers=available_servers,
            http_pool_maxsize=4,
            http_retry_timeout=40,
            http_retry_delay=_http_retry_delay,
        )

        try:
            login_or_register(client, signer=LocalSigner(private_key=decode_hex(self.private_key)))
        except (MatrixRequestError, ValueError):
            raise ConnectionError("Could not login/register to matrix.")

        try:
            room_name = make_room_alias(self.chain_id, service_room_suffix)
            monitoring_room = join_global_room(
                client=client, name=room_name, servers=available_servers
            )
        except (MatrixRequestError, TransportError):
            raise ConnectionError("Could not join monitoring broadcasting room.")

        return client, monitoring_room
Esempio n. 3
0
    def _start_client(self) -> None:
        try:
            login_or_register(
                self.client,
                signer=LocalSigner(private_key=decode_hex(self.private_key)))
        except (MatrixRequestError, ValueError):
            raise ConnectionError("Could not login/register to matrix.")

        try:
            room_name = make_room_alias(self.chain_id,
                                        self.service_room_suffix)
            self.broadcast_room = join_global_room(
                client=self.client,
                name=room_name,
                servers=self.available_servers)
        except (MatrixRequestError, TransportError):
            raise ConnectionError(
                "Could not join monitoring broadcasting room.")

        self.broadcast_room.add_listener(self._handle_message,
                                         "m.room.message")

        # Signal that startup is finished
        self.startup_finished.set()