Exemple #1
0
async def test_connection_wait_closed_exceptions(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"some_data")
    w.wait_closed.side_effect = ConnectionError
    connection = Connection(r, w)
    connection.close()
    await connection.wait_closed()

    r, w = rw_pairs_with_data(b"some_data")
    w.wait_closed.side_effect = TimeoutError
    connection = Connection(r, w)
    connection.close()
    await connection.wait_closed()
Exemple #2
0
async def test_connection_readexactly(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"something long")
    connection = Connection(r, w)
    data = await connection.readexactly(9)
    assert data == b"something"
    data = await connection.readexactly(3)
    assert data == b" lo"
Exemple #3
0
async def test_connection_read(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"foo")
    connection = Connection(r, w)
    data = await connection.read(10)
    assert data == b"foo"
    data = await connection.read(10)
    assert data == b""
Exemple #4
0
async def test_connection_rw(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"some_data")
    connection = Connection(r, w)

    data = await connection.read(4096)
    assert data == b"some_data"

    await connection.write(b"other_data")
    w.write.assert_called_with(b"other_data")
Exemple #5
0
async def test_connection_init(event_loop, mock_stream_writers):
    r = StreamReader(loop=event_loop)
    w = mock_stream_writers()
    connection = Connection(r, w)
    assert connection.reader is r
    assert connection.writer is w
    # Did we screw up __str__?
    str(connection)
    connection.add_header("foo")
    str(connection)
Exemple #6
0
 async def _make_connection(self, reader, writer):
     # By default asyncio streams keep around a fairly large write buffer -
     # something around 64kb. We already perform our own buffering and flow
     # control (via 5 minute replay delay and sending data after regular
     # timestamps), so we don't need it.
     # Bufferbloat like this can actually harm us - even though we sent the
     # game's header, it might take minutes before enough (delayed!) replay
     # data accumulates and everything is sent, and until then the game
     # won't load the map and appear frozen.
     writer.transport.set_write_buffer_limits(0)
     connection = Connection(reader, writer)
     await self._callback(connection)
Exemple #7
0
async def test_connection_closes(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"G/1/foo\0")
    connection = Connection(r, w)
    connection.close()
    w.transport.abort.assert_called()
Exemple #8
0
async def test_connection_readexactly_too_big(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"something")
    connection = Connection(r, w)
    with pytest.raises(MalformedDataError):
        await connection.readexactly(32)
Exemple #9
0
async def test_connection_readuntil_over_limit(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"some terminated string\0", limit=10)
    connection = Connection(r, w)
    with pytest.raises(MalformedDataError):
        await connection.readuntil(b"\0")
Exemple #10
0
async def test_connection_readuntil_no_delim(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"some unterminated string")
    connection = Connection(r, w)
    with pytest.raises(MalformedDataError):
        await connection.readuntil(b"\0")
Exemple #11
0
async def test_connection_readuntil(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"some string\0and some other string")
    connection = Connection(r, w)
    data = await connection.readuntil(b"\0")
    assert data == b"some string\0"
Exemple #12
0
async def test_connection_init(event_loop, mock_stream_writers):
    r = StreamReader(loop=event_loop)
    w = mock_stream_writers()
    connection = Connection(r, w)
    assert connection.reader is r
    assert connection.writer is w
Exemple #13
0
async def test_connection_readuntil_exception(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"bcd", exc=ConnectionError)
    connection = Connection(r, w)
    with pytest.raises(MalformedDataError):
        await connection.readuntil(b"a")
Exemple #14
0
async def test_connection_write_exception(rw_pairs_with_data):
    r, w = rw_pairs_with_data(b"some_data")
    w.write.side_effect = ConnectionError
    connection = Connection(r, w)
    with pytest.raises(MalformedDataError):
        await connection.write(b"other_data")
 async def _make_connection(self, reader, writer):
     connection = Connection(reader, writer)
     await self._callback(connection)