2018-11-21 12:25:49 +08:00
|
|
|
import asyncio
|
2018-11-21 12:49:37 +08:00
|
|
|
import pytest
|
2018-11-21 12:25:49 +08:00
|
|
|
|
2019-01-10 02:38:56 +08:00
|
|
|
|
2018-11-21 12:25:49 +08:00
|
|
|
async def handle_echo(reader, writer):
|
|
|
|
data = await reader.read(100)
|
|
|
|
writer.write(data)
|
|
|
|
await writer.drain()
|
|
|
|
writer.close()
|
|
|
|
|
2019-01-10 02:38:56 +08:00
|
|
|
|
2018-11-21 12:25:49 +08:00
|
|
|
@pytest.mark.asyncio
|
2018-11-27 07:24:29 +08:00
|
|
|
# TODO: this test should develop out into a fuller test between MPlex
|
|
|
|
# modules communicating with each other.
|
2018-11-21 12:49:37 +08:00
|
|
|
async def test_simple_echo():
|
2018-11-21 12:25:49 +08:00
|
|
|
server_ip = '127.0.0.1'
|
|
|
|
server_port = 8888
|
|
|
|
await asyncio.start_server(handle_echo, server_ip, server_port)
|
|
|
|
|
|
|
|
reader, writer = await asyncio.open_connection(server_ip, server_port)
|
2018-11-21 12:49:37 +08:00
|
|
|
|
2018-11-21 12:25:49 +08:00
|
|
|
test_message = "hello world"
|
|
|
|
writer.write(test_message.encode())
|
|
|
|
response = (await reader.read()).decode()
|
2018-11-21 12:49:37 +08:00
|
|
|
|
2018-11-21 12:25:49 +08:00
|
|
|
assert response == (test_message)
|