Skip to content

Commit

Permalink
Remove unused sync_channels strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
ichorid committed Dec 10, 2020
1 parent aa4b4b3 commit 5df91b8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@
from ipv8.peerdiscovery.discovery import DiscoveryStrategy


class SyncChannels(DiscoveryStrategy):
"""
Synchronization strategy for gigachannels.
On each tick we send a random peer some of our random subscribed channels.
"""

def take_step(self):
with self.walk_lock:
# Share my random channels
peers = self.overlay.get_peers()
if peers:
peer = choice(peers)
self.overlay.send_random_to(peer)


class RemovePeers(DiscoveryStrategy):
"""
Synchronization strategy for remote query community.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from ipv8.peerdiscovery.network import Network
from ipv8.test.base import TestBase

import pytest

from tribler_core.modules.metadata_store.community.sync_strategy import RemovePeers, SyncChannels
from tribler_core.modules.metadata_store.community.sync_strategy import RemovePeers


class MockCommunity(object):
Expand All @@ -25,51 +23,6 @@ def get_peers(self):
return self.get_peers_return


@pytest.fixture
def mock_community():
return MockCommunity()


@pytest.fixture
def strategy(mock_community):
return SyncChannels(mock_community)


def test_strategy_no_peers(mock_community, strategy):
"""
If we have no peers, no random entries should have been sent.
"""
strategy.take_step()
assert mock_community.send_random_to_called == []


def test_strategy_one_peer(mock_community, strategy):
"""
If we have one peer, we should send it our channel views and inspect our download queue.
"""
mock_community.get_peers_return = [Peer(default_eccrypto.generate_key(u"very-low"))]
strategy.take_step()

assert len(mock_community.send_random_to_called) == 1
assert mock_community.get_peers_return[0] == mock_community.send_random_to_called[0]


def test_strategy_multi_peer(mock_community, strategy):
"""
If we have multiple peers, we should select one and send it our channel views.
Also, we should still inspect our download queue.
"""
mock_community.get_peers_return = [
Peer(default_eccrypto.generate_key(u"very-low")),
Peer(default_eccrypto.generate_key(u"very-low")),
Peer(default_eccrypto.generate_key(u"very-low")),
]
strategy.take_step()

assert len(mock_community.send_random_to_called) == 1
assert mock_community.send_random_to_called[0] in mock_community.get_peers_return


class TestRemovePeers(TestBase):
def setUp(self):
self.community = MockCommunity()
Expand Down

0 comments on commit 5df91b8

Please sign in to comment.