Ejemplo n.º 1
0
def test_matrix_send_global(
    local_matrix_servers,
    retries_before_backoff,
    retry_interval,
    private_rooms,
):
    transport = MatrixTransport({
        'global_rooms': ['discovery', MONITORING_BROADCASTING_ROOM],
        'retries_before_backoff':
        retries_before_backoff,
        'retry_interval':
        retry_interval,
        'server':
        local_matrix_servers[0],
        'server_name':
        local_matrix_servers[0].netloc,
        'available_servers': [local_matrix_servers[0]],
        'private_rooms':
        private_rooms,
    })
    transport.start(MockRaidenService(None), MessageHandler(set()), '')
    gevent.idle()

    ms_room_name = make_room_alias(transport.network_id,
                                   MONITORING_BROADCASTING_ROOM)
    ms_room = transport._global_rooms.get(ms_room_name)
    assert isinstance(ms_room, Room)

    ms_room.send_text = MagicMock(spec=ms_room.send_text)

    for i in range(5):
        message = Processed(message_identifier=i)
        transport._raiden_service.sign(message)
        transport.send_global(
            MONITORING_BROADCASTING_ROOM,
            message,
        )
    transport._spawn(transport._global_send_worker)

    gevent.idle()

    assert ms_room.send_text.call_count >= 1
    # messages could have been bundled
    call_args_str = ' '.join(
        str(arg) for arg in ms_room.send_text.call_args_list)
    for i in range(5):
        assert f'"message_identifier": {i}' in call_args_str

    transport.stop()
    transport.get()
Ejemplo n.º 2
0
def test_matrix_send_global(
        local_matrix_servers,
        retries_before_backoff,
        retry_interval,
        private_rooms,
):
    transport = MatrixTransport({
        'global_rooms': ['discovery', 'monitoring'],
        'retries_before_backoff': retries_before_backoff,
        'retry_interval': retry_interval,
        'server': local_matrix_servers[0],
        'server_name': local_matrix_servers[0].netloc,
        'available_servers': [local_matrix_servers[0]],
        'private_rooms': private_rooms,
    })
    transport.start(MockRaidenService(None), MessageHandler(set()), '')
    gevent.idle()

    ms_room_name = transport._make_room_alias('monitoring')
    ms_room = transport._global_rooms.get(ms_room_name)
    assert isinstance(ms_room, Room)

    ms_room.send_text = MagicMock(spec=ms_room.send_text)

    for i in range(5):
        message = Processed(i)
        transport._raiden_service.sign(message)
        transport.send_global(
            'monitoring',
            message,
        )

    gevent.idle()

    assert ms_room.send_text.call_count == 5

    # unknown room suffix is an error
    with pytest.raises(AssertionError):
        transport.send_global(
            'unknown_suffix',
            Processed(10),
        )

    transport.stop()
    transport.get()
Ejemplo n.º 3
0
def test_matrix_send_global(
    local_matrix_servers,
    retries_before_backoff,
    retry_interval,
    private_rooms,
):
    transport = MatrixTransport({
        'global_rooms': ['discovery', MONITORING_BROADCASTING_ROOM],
        'retries_before_backoff':
        retries_before_backoff,
        'retry_interval':
        retry_interval,
        'server':
        local_matrix_servers[0],
        'server_name':
        local_matrix_servers[0].netloc,
        'available_servers': [local_matrix_servers[0]],
        'private_rooms':
        private_rooms,
    })
    transport.start(MockRaidenService(None), MessageHandler(set()), '')
    gevent.idle()

    ms_room_name = make_room_alias(transport.network_id,
                                   MONITORING_BROADCASTING_ROOM)
    ms_room = transport._global_rooms.get(ms_room_name)
    assert isinstance(ms_room, Room)

    ms_room.send_text = MagicMock(spec=ms_room.send_text)

    for i in range(5):
        message = Processed(i)
        transport._raiden_service.sign(message)
        transport.send_global(
            MONITORING_BROADCASTING_ROOM,
            message,
        )

    gevent.idle()

    assert ms_room.send_text.call_count == 5

    transport.stop()
    transport.get()