From fd9bc6214a6c55fee3888be80d3d5a5cbe94ea00 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 3 Oct 2016 15:40:27 -0400 Subject: [PATCH] fix functional tests --- lbrynet/core/BlobAvailability.py | 18 ++++++++---- lbrynet/core/Session.py | 4 +-- lbrynet/core/server/BlobRequestHandler.py | 6 ++-- tests/functional/test_misc.py | 35 ++++++++++++++++------- tests/functional/test_reflector.py | 7 ++++- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/lbrynet/core/BlobAvailability.py b/lbrynet/core/BlobAvailability.py index 9cbbb3ec6..5acd62b89 100644 --- a/lbrynet/core/BlobAvailability.py +++ b/lbrynet/core/BlobAvailability.py @@ -2,6 +2,7 @@ import logging from twisted.internet import defer from twisted.internet.task import LoopingCall +from lbrynet.core.PeerFinder import DummyPeerFinder log = logging.getLogger(__name__) @@ -88,7 +89,7 @@ class BlobAvailabilityTracker(object): self.last_mean_availability = mean -class DummyBlobAvailabilityTracker(object): +class DummyBlobAvailabilityTracker(BlobAvailabilityTracker): """ Class to track peer counts for known blobs, and to discover new popular blobs @@ -109,9 +110,16 @@ class DummyBlobAvailabilityTracker(object): 'f99d24cd50d4bfd77c2598bfbeeb8415bf0feef21200bdf0b8fbbde7751a77b7a2c68e09c25465a2f40fba8eecb0b4e0': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'], 'c84aa1fd8f5009f7c4e71e444e40d95610abc1480834f835eefb267287aeb10025880a3ce22580db8c6d92efb5bc0c9c': ['1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4', '1.2.3.4'], } + self.last_mean_availability = 0.0 + self._blob_manager = None + self._peer_finder = DummyPeerFinder() + self._dht_node = None + self._check_popular = None + self._check_mine = None self._get_mean_peers() - def _get_mean_peers(self): - num_peers = [len(self.availability[blob]) for blob in self.availability] - mean = float(sum(num_peers)) / float(max(1, len(num_peers))) - self.last_mean_availability = mean + def start(self): + pass + + def stop(self): + pass diff --git a/lbrynet/core/Session.py b/lbrynet/core/Session.py index 370b718d8..c85b7c0dd 100644 --- a/lbrynet/core/Session.py +++ b/lbrynet/core/Session.py @@ -295,7 +295,7 @@ class Session(object): return d def _subfailure(self, err): - log.warning(err.getTraceback()) - return err.value.subFailure + log.error(err.getTraceback()) + return err.value diff --git a/lbrynet/core/server/BlobRequestHandler.py b/lbrynet/core/server/BlobRequestHandler.py index 0b9b5cb6b..138a0695a 100644 --- a/lbrynet/core/server/BlobRequestHandler.py +++ b/lbrynet/core/server/BlobRequestHandler.py @@ -110,7 +110,7 @@ class BlobRequestHandler(object): def open_blob_for_reading(self, blob, response): def failure(msg): - log.warning("We can not send %s: %s", blob, msg) + log.debug("We can not send %s: %s", blob, msg) response['incoming_blob'] = {'error': 'BLOB_UNAVAILABLE'} return response if not blob.is_validated(): @@ -168,7 +168,7 @@ class BlobRequestHandler(object): d.addCallback(lambda _: self.record_transaction(blob)) d.addCallback(lambda _: response) return d - log.warning("We can not send %s", str(blob)) + log.debug("We can not send %s", str(blob)) response['incoming_blob'] = {'error': 'BLOB_UNAVAILABLE'} d.addCallback(lambda _: response) return d @@ -183,7 +183,7 @@ class BlobRequestHandler(object): rate = self.blob_data_payment_rate if self.blob_data_payment_rate is None: - log.warning("Rate not set yet") + log.debug("Rate not set yet") response['incoming_blob'] = {'error': 'RATE_UNSET'} return defer.succeed(response) else: diff --git a/tests/functional/test_misc.py b/tests/functional/test_misc.py index 28a489c50..840780268 100644 --- a/tests/functional/test_misc.py +++ b/tests/functional/test_misc.py @@ -32,6 +32,7 @@ from twisted.internet import defer, threads, task, error from twisted.trial.unittest import TestCase from twisted.python.failure import Failure import os +from lbrynet.core.BlobAvailability import DummyBlobAvailabilityTracker from lbrynet.core.PeerManager import PeerManager from lbrynet.core.RateLimiter import DummyRateLimiter, RateLimiter from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory @@ -237,13 +238,14 @@ def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rat hash_announcer = FakeAnnouncer() rate_limiter = RateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "server" os.mkdir(db_dir) session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) stream_info_manager = TempEncryptedFileMetadataManager() @@ -352,6 +354,7 @@ def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_ra hash_announcer = FakeAnnouncer() rate_limiter = RateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "server_" + str(n) blob_dir = os.path.join(db_dir, "blobfiles") @@ -361,7 +364,7 @@ def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_ra session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd" + str(n), peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None, peer_port=peer_port, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) stream_info_manager = TempEncryptedFileMetadataManager() @@ -468,13 +471,14 @@ def start_live_server(sd_hash_queue, kill_event, dead_event): hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "server" os.mkdir(db_dir) session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) base_payment_rate_manager = BaseLiveStreamPaymentRateManager(MIN_BLOB_INFO_PAYMENT_RATE) data_payment_rate_manager = session.payment_rate_manager @@ -606,6 +610,7 @@ def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow): peer_finder = FakePeerFinder(5553, peer_manager, 1) hash_announcer = FakeAnnouncer() rate_limiter = RateLimiter() + blob_tracker = DummyBlobAvailabilityTracker() if slow is True: peer_port = 5553 @@ -620,7 +625,7 @@ def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow): session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="efgh", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=blob_dir, peer_port=peer_port, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) if slow is True: session.rate_limiter.set_ul_limit(2**11) @@ -783,6 +788,7 @@ class TestTransfer(TestCase): hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "client" blob_dir = os.path.join(db_dir, "blobfiles") @@ -792,7 +798,7 @@ class TestTransfer(TestCase): self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=blob_dir, peer_port=5553, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) self.stream_info_manager = TempEncryptedFileMetadataManager() @@ -870,13 +876,15 @@ class TestTransfer(TestCase): hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "client" os.mkdir(db_dir) self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None, - peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, + blob_tracker=blob_tracker) self.stream_info_manager = TempLiveStreamMetadataManager(hash_announcer) @@ -973,6 +981,7 @@ class TestTransfer(TestCase): peer_finder = FakePeerFinder(5553, peer_manager, 2) hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "client" blob_dir = os.path.join(db_dir, "blobfiles") @@ -982,7 +991,7 @@ class TestTransfer(TestCase): self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=blob_dir, peer_port=5553, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) d1 = self.wait_for_hash_from_queue(blob_hash_queue_1) d2 = self.wait_for_hash_from_queue(blob_hash_queue_2) @@ -1051,6 +1060,7 @@ class TestTransfer(TestCase): hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() downloaders = [] @@ -1062,7 +1072,7 @@ class TestTransfer(TestCase): self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=blob_dir, peer_port=5553, use_upnp=False, - rate_limiter=rate_limiter, wallet=wallet) + rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) self.stream_info_manager = DBEncryptedFileMetadataManager(self.session.db_dir) @@ -1169,6 +1179,7 @@ class TestTransfer(TestCase): hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "client" blob_dir = os.path.join(db_dir, "blobfiles") @@ -1178,7 +1189,7 @@ class TestTransfer(TestCase): self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=None, peer_port=5553, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) self.stream_info_manager = TempEncryptedFileMetadataManager() @@ -1287,6 +1298,7 @@ class TestStreamify(TestCase): hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "client" blob_dir = os.path.join(db_dir, "blobfiles") @@ -1296,7 +1308,7 @@ class TestStreamify(TestCase): self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=blob_dir, peer_port=5553, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) self.stream_info_manager = TempEncryptedFileMetadataManager() @@ -1339,6 +1351,7 @@ class TestStreamify(TestCase): hash_announcer = FakeAnnouncer() rate_limiter = DummyRateLimiter() sd_identifier = StreamDescriptorIdentifier() + blob_tracker = DummyBlobAvailabilityTracker() db_dir = "client" blob_dir = os.path.join(db_dir, "blobfiles") @@ -1348,7 +1361,7 @@ class TestStreamify(TestCase): self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", peer_finder=peer_finder, hash_announcer=hash_announcer, blob_dir=blob_dir, peer_port=5553, - use_upnp=False, rate_limiter=rate_limiter, wallet=wallet) + use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker) self.stream_info_manager = DBEncryptedFileMetadataManager(self.session.db_dir) diff --git a/tests/functional/test_reflector.py b/tests/functional/test_reflector.py index c3ce00ca5..8c26fb364 100644 --- a/tests/functional/test_reflector.py +++ b/tests/functional/test_reflector.py @@ -12,6 +12,8 @@ from lbrynet.core import PeerManager from lbrynet.core import RateLimiter from lbrynet.core import Session from lbrynet.core import StreamDescriptor +from lbrynet.core import BlobAvailability +from lbrynet.dht.node import Node from lbrynet.lbryfile import EncryptedFileMetadataManager from lbrynet.lbryfile.client import EncryptedFileOptions from lbrynet.lbryfilemanager import EncryptedFileCreator @@ -59,6 +61,7 @@ class TestReflector(unittest.TestCase): hash_announcer = mocks.Announcer() rate_limiter = RateLimiter.DummyRateLimiter() sd_identifier = StreamDescriptor.StreamDescriptorIdentifier() + blob_tracker = BlobAvailability.DummyBlobAvailabilityTracker() self.expected_blobs = [ ( @@ -91,7 +94,9 @@ class TestReflector(unittest.TestCase): peer_port=5553, use_upnp=False, rate_limiter=rate_limiter, - wallet=wallet + wallet=wallet, + blob_tracker=blob_tracker, + dht_node_class=Node ) self.stream_info_manager = EncryptedFileMetadataManager.TempEncryptedFileMetadataManager()