mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
makes test_mplex_stream.py::test_mplex_stream_read_write work
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import trio
|
||||
import multiaddr
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
@ -24,11 +24,11 @@ async def test_simple_messages(nursery):
|
||||
# Associate the peer with local ip address (see default parameters of Libp2p())
|
||||
node_a.get_peerstore().add_addrs(node_b.get_id(), node_b.get_addrs(), 10)
|
||||
|
||||
|
||||
stream = await node_a.new_stream(node_b.get_id(), ["/echo/1.0.0"])
|
||||
|
||||
messages = ["hello" + str(x) for x in range(10)]
|
||||
for message in messages:
|
||||
|
||||
await stream.write(message.encode())
|
||||
|
||||
response = (await stream.read(MAX_READ_LEN)).decode()
|
||||
|
||||
@ -1,20 +1,31 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.stream_muxer.mplex.exceptions import (
|
||||
MplexStreamClosed,
|
||||
MplexStreamEOF,
|
||||
MplexStreamReset,
|
||||
)
|
||||
from libp2p.tools.constants import MAX_READ_LEN
|
||||
from libp2p.tools.constants import MAX_READ_LEN, LISTEN_MADDR
|
||||
from libp2p.tools.factories import SwarmFactory
|
||||
from libp2p.tools.utils import connect_swarm
|
||||
|
||||
DATA = b"data_123"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mplex_stream_read_write(mplex_stream_pair):
|
||||
stream_0, stream_1 = mplex_stream_pair
|
||||
@pytest.mark.trio
|
||||
async def test_mplex_stream_read_write(nursery):
|
||||
swarm0, swarm1 = SwarmFactory(), SwarmFactory()
|
||||
await swarm0.listen(LISTEN_MADDR, nursery=nursery)
|
||||
await swarm1.listen(LISTEN_MADDR, nursery=nursery)
|
||||
await connect_swarm(swarm0, swarm1, nursery)
|
||||
conn_0 = swarm0.connections[swarm1.get_peer_id()]
|
||||
conn_1 = swarm1.connections[swarm0.get_peer_id()]
|
||||
stream_0 = await conn_0.muxed_conn.open_stream()
|
||||
await trio.sleep(1)
|
||||
stream_1 = tuple(conn_1.muxed_conn.streams.values())[0]
|
||||
await stream_0.write(DATA)
|
||||
assert (await stream_1.read(MAX_READ_LEN)) == DATA
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import trio
|
||||
import pytest
|
||||
import trio
|
||||
|
||||
from libp2p.utils import TrioQueue
|
||||
|
||||
|
||||
@ -16,4 +17,3 @@ async def test_trio_queue():
|
||||
result = await nursery.start(queue_get)
|
||||
|
||||
assert result == 123
|
||||
|
||||
|
||||
Reference in New Issue
Block a user