From f3732f94809e2ae7314641bcb066be6222370d9d Mon Sep 17 00:00:00 2001 From: NIC619 Date: Wed, 18 Dec 2019 12:37:04 +0800 Subject: [PATCH] Fix tests --- libp2p/pubsub/gossipsub.py | 4 +++- tests/pubsub/test_gossipsub.py | 16 ++++++++-------- tests_interop/test_pubsub.py | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index 55029cdb..51e1c92c 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -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] diff --git a/tests/pubsub/test_gossipsub.py b/tests/pubsub/test_gossipsub.py index 19ec07c5..fe6bf3b8 100644 --- a/tests/pubsub/test_gossipsub.py +++ b/tests/pubsub/test_gossipsub.py @@ -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) diff --git a/tests_interop/test_pubsub.py b/tests_interop/test_pubsub.py index f67b47ab..db42c7cd 100644 --- a/tests_interop/test_pubsub.py +++ b/tests_interop/test_pubsub.py @@ -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)