mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Fix tests
This commit is contained in:
@ -719,7 +719,9 @@ class GossipSub(IPubsubRouter):
|
||||
|
||||
# Get stream for peer from pubsub
|
||||
if to_peer not in self.pubsub.peers:
|
||||
logger.debug("Fail to emit control message to %s: peer disconnected", to_peer)
|
||||
logger.debug(
|
||||
"Fail to emit control message to %s: peer disconnected", to_peer
|
||||
)
|
||||
return
|
||||
peer_stream = self.pubsub.peers[to_peer]
|
||||
|
||||
|
||||
@ -390,15 +390,15 @@ async def test_mesh_heartbeat(
|
||||
fake_peer_ids = [
|
||||
ID((i).to_bytes(2, byteorder="big")) for i in range(total_peer_count)
|
||||
]
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router, "peers_gossipsub", fake_peer_ids)
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router, "peers_gossipsub", set(fake_peer_ids))
|
||||
|
||||
peer_topics = {topic: fake_peer_ids}
|
||||
peer_topics = {topic: set(fake_peer_ids)}
|
||||
# Monkeypatch the peer subscriptions
|
||||
monkeypatch.setattr(pubsubs_gsub[0], "peer_topics", peer_topics)
|
||||
|
||||
mesh_peer_indices = random.sample(range(total_peer_count), initial_mesh_peer_count)
|
||||
mesh_peers = [fake_peer_ids[i] for i in mesh_peer_indices]
|
||||
router_mesh = {topic: list(mesh_peers)}
|
||||
router_mesh = {topic: set(mesh_peers)}
|
||||
# Monkeypatch our mesh peers
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router, "mesh", router_mesh)
|
||||
|
||||
@ -437,27 +437,27 @@ async def test_gossip_heartbeat(
|
||||
fake_peer_ids = [
|
||||
ID((i).to_bytes(2, byteorder="big")) for i in range(total_peer_count)
|
||||
]
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router, "peers_gossipsub", fake_peer_ids)
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router, "peers_gossipsub", set(fake_peer_ids))
|
||||
|
||||
topic_mesh_peer_count = 14
|
||||
# Split into mesh peers and fanout peers
|
||||
peer_topics = {
|
||||
topic_mesh: fake_peer_ids[:topic_mesh_peer_count],
|
||||
topic_fanout: fake_peer_ids[topic_mesh_peer_count:],
|
||||
topic_mesh: set(fake_peer_ids[:topic_mesh_peer_count]),
|
||||
topic_fanout: set(fake_peer_ids[topic_mesh_peer_count:]),
|
||||
}
|
||||
# Monkeypatch the peer subscriptions
|
||||
monkeypatch.setattr(pubsubs_gsub[0], "peer_topics", peer_topics)
|
||||
|
||||
mesh_peer_indices = random.sample(range(topic_mesh_peer_count), initial_peer_count)
|
||||
mesh_peers = [fake_peer_ids[i] for i in mesh_peer_indices]
|
||||
router_mesh = {topic_mesh: list(mesh_peers)}
|
||||
router_mesh = {topic_mesh: set(mesh_peers)}
|
||||
# Monkeypatch our mesh peers
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router, "mesh", router_mesh)
|
||||
fanout_peer_indices = random.sample(
|
||||
range(topic_mesh_peer_count, total_peer_count), initial_peer_count
|
||||
)
|
||||
fanout_peers = [fake_peer_ids[i] for i in fanout_peer_indices]
|
||||
router_fanout = {topic_fanout: list(fanout_peers)}
|
||||
router_fanout = {topic_fanout: set(fanout_peers)}
|
||||
# Monkeypatch our fanout peers
|
||||
monkeypatch.setattr(pubsubs_gsub[0].router, "fanout", router_fanout)
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ async def test_pubsub(pubsubs, p2pds):
|
||||
go_0_topic_1_peers = await p2pds[0].control.pubsub_list_peers(TOPIC_1)
|
||||
assert len(go_0_topic_1_peers) == 1 and py_peer_id == go_0_topic_1_peers[0]
|
||||
# py
|
||||
py_topic_0_peers = py_pubsub.peer_topics[TOPIC_0]
|
||||
py_topic_0_peers = list(py_pubsub.peer_topics[TOPIC_0])
|
||||
assert len(py_topic_0_peers) == 1 and p2pds[0].peer_id == py_topic_0_peers[0]
|
||||
# go_1
|
||||
go_1_topic_1_peers = await p2pds[1].control.pubsub_list_peers(TOPIC_1)
|
||||
|
||||
Reference in New Issue
Block a user