async def test_merger_successful_connection(event_loop, mock_connections,
                                            data_send_mixin):
    conn = mock_connections()
    replay_data = example_replay.data
    data_send_mixin(conn, replay_data, 0.25, 200)

    merger = Merger.build(**config)
    await merger.handle_connection(conn)
    await verify_merger_ending_with_data(merger, replay_data)
async def test_merger_successful_connection(event_loop, mock_connections,
                                            mock_conn_read_data_mixin):
    conn = mock_connections()
    mock_conn_read_data_mixin(conn, example_replay.data, 0.25, 200)

    merger = Merger.build(merger_config(merger_dict),
                          delay_config(delay_dict))
    await merger.handle_connection(conn)
    await verify_merger_ending_with_data(merger, example_replay.data)
async def test_merger_incomplete_header(event_loop, mock_connections,
                                        data_send_mixin):
    conn = mock_connections()
    replay_data = example_replay.header_data[:-100]
    data_send_mixin(conn, replay_data, 0.25, 200)

    merger = Merger.build(**config)
    with pytest.raises(MalformedDataError):
        await merger.handle_connection(conn)
    await verify_merger_ending_with_data(merger, None)
async def test_merger_closes_fast(event_loop, mock_connections,
                                  data_send_mixin):
    conn = mock_connections()
    replay_data = example_replay.data
    data_send_mixin(conn, replay_data, 0.6, 160)

    merger = Merger.build(**config)
    f = asyncio.ensure_future(merger.handle_connection(conn))
    await asyncio.sleep(45)
    conn.read.side_effect = lambda _: b""   # Simulate connection.close()
    merger.close()
    await asyncio.wait_for(merger.wait_for_ended(), 1)
    await asyncio.wait_for(f, 1)
async def test_merger_ends(event_loop, mock_connections, data_send_mixin):
    conn_1 = mock_connections()
    conn_2 = mock_connections()
    replay_data = example_replay.data

    data_send_mixin(conn_1, replay_data, 0.6, 160)
    data_send_mixin(conn_2, replay_data, 0.6, 160)

    merger = Merger.build(**config)
    await merger.handle_connection(conn_1)
    await asyncio.sleep(45)
    with pytest.raises(CannotAcceptConnectionError):
        await merger.handle_connection(conn_2)
    await verify_merger_ending_with_data(merger, replay_data)
async def test_merger_sequential_connections(event_loop, mock_connections,
                                             data_send_mixin):
    conn_1 = mock_connections()
    conn_2 = mock_connections()
    replay_data = example_replay.data

    # First has incomplete data, but sends faster
    data_send_mixin(conn_1, replay_data[:-100], 0.4, 160)
    data_send_mixin(conn_2, replay_data, 0.6, 160)

    merger = Merger.build(**config)
    await merger.handle_connection(conn_1)
    await asyncio.sleep(15)
    await merger.handle_connection(conn_2)
    await verify_merger_ending_with_data(merger, replay_data)
async def test_merger_incomplete_header_then_data(event_loop,
                                                  mock_connections,
                                                  mock_conn_read_data_mixin):
    conn_1 = mock_connections()
    conn_2 = mock_connections()
    replay_data = example_replay.header_data[:-100]
    mock_conn_read_data_mixin(conn_1, replay_data, 0.25, 200)
    mock_conn_read_data_mixin(conn_2, example_replay.data, 0.25, 200)

    merger = Merger.build(merger_config(merger_dict),
                          delay_config(delay_dict))
    with pytest.raises(MalformedDataError):
        await merger.handle_connection(conn_1)
    await merger.handle_connection(conn_2)

    await verify_merger_ending_with_data(merger, example_replay.data)
async def test_merger_refuses_conns(event_loop, mock_connections,
                                    mock_conn_read_data_mixin):
    conn_1 = mock_connections()
    conn_2 = mock_connections()
    replay_data = example_replay.data

    mock_conn_read_data_mixin(conn_1, replay_data, 0.6, 160)
    mock_conn_read_data_mixin(conn_2, replay_data, 0.6, 160)

    merger = Merger.build(merger_config(merger_dict),
                          delay_config(delay_dict))
    await merger.handle_connection(conn_1)
    merger.stop_accepting_connections()
    with pytest.raises(CannotAcceptConnectionError):
        await merger.handle_connection(conn_2)
    await verify_merger_ending_with_data(merger, example_replay.data)
async def test_merger_two_connections(event_loop, mock_connections,
                                      data_send_mixin):
    conn_1 = mock_connections()
    conn_2 = mock_connections()
    replay_data = example_replay.data

    # First has incomplete data, but sends faster
    data_send_mixin(conn_1, replay_data[:-100], 0.4, 160)
    data_send_mixin(conn_2, replay_data, 0.6, 160)

    merger = Merger.build(**config)
    f_1 = asyncio.ensure_future(merger.handle_connection(conn_1))
    f_2 = asyncio.ensure_future(merger.handle_connection(conn_2))
    await f_1
    await f_2
    await verify_merger_ending_with_data(merger, replay_data)
示例#10
0
 def build(cls, game_id, bookkeeper, config):
     merger = Merger.build(config.merge, config.delay)
     sender = Sender.build(merger.canonical_stream)
     return cls(merger, sender, bookkeeper, config, game_id)
def test_merger_init():
    Merger.build(merger_config(merger_dict),
                 delay_config(delay_dict))
示例#12
0
 def build(cls, game_id, bookkeeper, *, config_replay_forced_end_time,
           **kwargs):
     merger = Merger.build(**kwargs)
     sender = Sender.build(merger.canonical_stream, **kwargs)
     return cls(merger, sender, bookkeeper, config_replay_forced_end_time,
                game_id)
def test_merger_init():
    Merger.build(**config)