py-libp2p/tests/network/test_connection.py

28 lines
690 B
Python
Raw Normal View History

2018-11-21 12:25:49 +08:00
import asyncio
2019-08-03 13:36:19 +08:00
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
# 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():
2019-08-01 06:00:12 +08:00
server_ip = "127.0.0.1"
2018-11-21 12:25:49 +08:00
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)