py-libp2p/tests/network/test_connection.py

28 lines
718 B
Python
Raw Normal View History

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
2018-11-21 12:49:37 +08:00
# from network.connection.raw_connection import RawConnection
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()
@pytest.mark.asyncio
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
# raw_connection = RawConnection(server_ip, server_port, reader, writer)
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)