mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-11 07:30:55 +00:00
raw_connection echo test
This commit is contained in:
0
tests/network/__init__.py
Normal file
0
tests/network/__init__.py
Normal file
29
tests/network/test_connection.py
Normal file
29
tests/network/test_connection.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import pytest
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from network.connection.raw_connection import RawConnection
|
||||||
|
|
||||||
|
|
||||||
|
async def handle_echo(reader, writer):
|
||||||
|
data = await reader.read(100)
|
||||||
|
message = data.decode()
|
||||||
|
|
||||||
|
writer.write(data)
|
||||||
|
await writer.drain()
|
||||||
|
|
||||||
|
writer.close()
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_echo():
|
||||||
|
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)
|
||||||
|
raw_connection = RawConnection(server_ip, server_port, reader, writer)
|
||||||
|
|
||||||
|
test_message = "hello world"
|
||||||
|
writer.write(test_message.encode())
|
||||||
|
response = (await reader.read()).decode()
|
||||||
|
|
||||||
|
assert response == (test_message)
|
||||||
Reference in New Issue
Block a user