Beispiel #1
0
async def test_merger_no_connection_wait_active_connection(
        outside_source_stream, mock_merge_strategy, mock_reader_builder,
        mock_delayed_stream_builder, mock_readers, mock_connections,
        event_loop):
    connection = mock_connections()
    reader = mock_readers()
    mock_reader_builder.side_effect = [reader]
    canonical_stream = outside_source_stream

    async def long_read():
        await asyncio.sleep(0.05)
        return

    reader.read.side_effect = long_read

    merger = Merger(mock_reader_builder, mock_delayed_stream_builder,
                    mock_merge_strategy, canonical_stream)
    f = asyncio.ensure_future(merger.no_connections_for(0.01))
    h = asyncio.ensure_future(merger.handle_connection(connection))

    await asyncio.sleep(0.02)
    exhaust_callbacks(event_loop)
    assert not f.done()
    await h
    exhaust_callbacks(event_loop)
    assert not f.done()
    await asyncio.sleep(0.02)
    exhaust_callbacks(event_loop)
    assert f.done()
    await f

    merger.stop_accepting_connections()
    await merger.wait_for_ended()
Beispiel #2
0
async def test_merger_no_connections_wait_empty(outside_source_stream,
                                                mock_merge_strategy,
                                                mock_reader_builder,
                                                mock_delayed_stream_builder,
                                                event_loop):
    canonical_stream = outside_source_stream
    merger = Merger(mock_reader_builder, mock_delayed_stream_builder,
                    mock_merge_strategy, canonical_stream)
    f = asyncio.ensure_future(merger.no_connections_for(0.01))
    exhaust_callbacks(event_loop)
    assert not f.done()
    await asyncio.sleep(0.02)
    exhaust_callbacks(event_loop)
    assert f.done()
    await f

    merger.stop_accepting_connections()
    await merger.wait_for_ended()