mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-10 15:10:54 +00:00
Merge branch 'master' into feature/porting-to-trio
This commit is contained in:
@ -4,6 +4,7 @@ import trio
|
||||
|
||||
from libp2p.network.connection.raw_connection import RawConnection
|
||||
from libp2p.tools.constants import LISTEN_MADDR
|
||||
from libp2p.transport.exceptions import OpenConnectionError
|
||||
from libp2p.transport.tcp.tcp import TCP
|
||||
|
||||
|
||||
@ -26,14 +27,17 @@ async def test_tcp_listener(nursery):
|
||||
async def test_tcp_dial(nursery):
|
||||
transport = TCP()
|
||||
raw_conn_other_side = None
|
||||
event = trio.Event()
|
||||
|
||||
async def handler(tcp_stream):
|
||||
nonlocal raw_conn_other_side
|
||||
raw_conn_other_side = RawConnection(tcp_stream, False)
|
||||
event.set()
|
||||
await trio.sleep_forever()
|
||||
|
||||
# Test: OSError is raised when trying to dial to a port which no one is not listening to.
|
||||
with pytest.raises(OSError):
|
||||
# Test: `OpenConnectionError` is raised when trying to dial to a port which
|
||||
# no one is not listening to.
|
||||
with pytest.raises(OpenConnectionError):
|
||||
await transport.dial(Multiaddr("/ip4/127.0.0.1/tcp/1"))
|
||||
|
||||
listener = transport.create_listener(handler)
|
||||
@ -42,6 +46,7 @@ async def test_tcp_dial(nursery):
|
||||
assert len(addrs) == 1
|
||||
listen_addr = addrs[0]
|
||||
raw_conn = await transport.dial(listen_addr)
|
||||
await event.wait()
|
||||
|
||||
data = b"123"
|
||||
await raw_conn_other_side.write(data)
|
||||
|
||||
Reference in New Issue
Block a user