mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-11 15:40:54 +00:00
Add is_gossipsub fixture in interop test
To use the same code to test against both routers: floodsub and gossipsub.
This commit is contained in:
@ -4,6 +4,9 @@ import sys
|
||||
import pexpect
|
||||
import pytest
|
||||
|
||||
from tests.factories import FloodsubFactory, GossipsubFactory, PubsubFactory
|
||||
from tests.pubsub.configs import GOSSIPSUB_PARAMS
|
||||
|
||||
from .daemon import make_p2pd
|
||||
|
||||
|
||||
@ -33,11 +36,35 @@ def num_p2pds():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def p2pds(num_p2pds, is_host_secure, unused_tcp_port_factory):
|
||||
def is_gossipsub():
|
||||
return True
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def p2pds(num_p2pds, is_host_secure, is_gossipsub, unused_tcp_port_factory):
|
||||
p2pds = await asyncio.gather(
|
||||
*[make_p2pd(unused_tcp_port_factory, is_host_secure) for _ in range(num_p2pds)]
|
||||
*[
|
||||
make_p2pd(
|
||||
unused_tcp_port_factory, is_host_secure, is_gossipsub=is_gossipsub
|
||||
)
|
||||
for _ in range(num_p2pds)
|
||||
]
|
||||
)
|
||||
try:
|
||||
yield p2pds
|
||||
finally:
|
||||
await asyncio.gather(*[p2pd.close() for p2pd in p2pds])
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pubsubs(num_hosts, hosts, is_gossipsub):
|
||||
routers = None
|
||||
if is_gossipsub:
|
||||
routers = GossipsubFactory.create_batch(num_hosts, **GOSSIPSUB_PARAMS._asdict())
|
||||
else:
|
||||
routers = FloodsubFactory.create_batch(num_hosts)
|
||||
_pubsubs = tuple(
|
||||
PubsubFactory(host=host, router=router) for host, router in zip(hosts, routers)
|
||||
)
|
||||
yield _pubsubs
|
||||
# TODO: Clean up
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
import asyncio
|
||||
import functools
|
||||
|
||||
from p2pclient.pb import p2pd_pb2
|
||||
import pytest
|
||||
|
||||
from libp2p.peer.id import ID
|
||||
from libp2p.utils import read_varint_prefixed_bytes
|
||||
from libp2p.pubsub.pb import rpc_pb2
|
||||
|
||||
from p2pclient.pb import p2pd_pb2
|
||||
from libp2p.utils import read_varint_prefixed_bytes
|
||||
|
||||
from .utils import connect
|
||||
|
||||
@ -57,13 +56,14 @@ def validate_pubsub_msg(msg: rpc_pb2.Message, data: bytes, from_peer_id: ID) ->
|
||||
assert msg.data == data and msg.from_id == from_peer_id
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_gossipsub", (True, False))
|
||||
@pytest.mark.parametrize("num_hosts, num_p2pds", ((1, 2),))
|
||||
@pytest.mark.asyncio
|
||||
async def test_pubsub(pubsubs_gsub, p2pds):
|
||||
async def test_pubsub(pubsubs, p2pds):
|
||||
#
|
||||
# Test: Recognize pubsub peers on connection.
|
||||
#
|
||||
py_pubsub = pubsubs_gsub[0]
|
||||
py_pubsub = pubsubs[0]
|
||||
# go0 <-> py <-> go1
|
||||
await connect(p2pds[0], py_pubsub.host)
|
||||
await connect(py_pubsub.host, p2pds[1])
|
||||
|
||||
Reference in New Issue
Block a user