fix functional tests

This commit is contained in:
Jack 2016-10-03 15:40:27 -04:00
parent b3f3ed8026
commit fd9bc6214a
5 changed files with 48 additions and 22 deletions

View file

@ -2,6 +2,7 @@ import logging
from twisted.internet import defer from twisted.internet import defer
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
from lbrynet.core.PeerFinder import DummyPeerFinder
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -88,7 +89,7 @@ class BlobAvailabilityTracker(object):
self.last_mean_availability = mean 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 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'], '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'], '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() self._get_mean_peers()
def _get_mean_peers(self): def start(self):
num_peers = [len(self.availability[blob]) for blob in self.availability] pass
mean = float(sum(num_peers)) / float(max(1, len(num_peers)))
self.last_mean_availability = mean def stop(self):
pass

View file

@ -295,7 +295,7 @@ class Session(object):
return d return d
def _subfailure(self, err): def _subfailure(self, err):
log.warning(err.getTraceback()) log.error(err.getTraceback())
return err.value.subFailure return err.value

View file

@ -110,7 +110,7 @@ class BlobRequestHandler(object):
def open_blob_for_reading(self, blob, response): def open_blob_for_reading(self, blob, response):
def failure(msg): 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'} response['incoming_blob'] = {'error': 'BLOB_UNAVAILABLE'}
return response return response
if not blob.is_validated(): if not blob.is_validated():
@ -168,7 +168,7 @@ class BlobRequestHandler(object):
d.addCallback(lambda _: self.record_transaction(blob)) d.addCallback(lambda _: self.record_transaction(blob))
d.addCallback(lambda _: response) d.addCallback(lambda _: response)
return d 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'} response['incoming_blob'] = {'error': 'BLOB_UNAVAILABLE'}
d.addCallback(lambda _: response) d.addCallback(lambda _: response)
return d return d
@ -183,7 +183,7 @@ class BlobRequestHandler(object):
rate = self.blob_data_payment_rate rate = self.blob_data_payment_rate
if self.blob_data_payment_rate is None: 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'} response['incoming_blob'] = {'error': 'RATE_UNSET'}
return defer.succeed(response) return defer.succeed(response)
else: else:

View file

@ -32,6 +32,7 @@ from twisted.internet import defer, threads, task, error
from twisted.trial.unittest import TestCase from twisted.trial.unittest import TestCase
from twisted.python.failure import Failure from twisted.python.failure import Failure
import os import os
from lbrynet.core.BlobAvailability import DummyBlobAvailabilityTracker
from lbrynet.core.PeerManager import PeerManager from lbrynet.core.PeerManager import PeerManager
from lbrynet.core.RateLimiter import DummyRateLimiter, RateLimiter from lbrynet.core.RateLimiter import DummyRateLimiter, RateLimiter
from lbrynet.core.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory 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() hash_announcer = FakeAnnouncer()
rate_limiter = RateLimiter() rate_limiter = RateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "server" db_dir = "server"
os.mkdir(db_dir) os.mkdir(db_dir)
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553, 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() 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() hash_announcer = FakeAnnouncer()
rate_limiter = RateLimiter() rate_limiter = RateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "server_" + str(n) db_dir = "server_" + str(n)
blob_dir = os.path.join(db_dir, "blobfiles") 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), session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd" + str(n),
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=peer_port, 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() stream_info_manager = TempEncryptedFileMetadataManager()
@ -468,13 +471,14 @@ def start_live_server(sd_hash_queue, kill_event, dead_event):
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "server" db_dir = "server"
os.mkdir(db_dir) os.mkdir(db_dir)
session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_port=5553, 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) base_payment_rate_manager = BaseLiveStreamPaymentRateManager(MIN_BLOB_INFO_PAYMENT_RATE)
data_payment_rate_manager = session.payment_rate_manager 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) peer_finder = FakePeerFinder(5553, peer_manager, 1)
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = RateLimiter() rate_limiter = RateLimiter()
blob_tracker = DummyBlobAvailabilityTracker()
if slow is True: if slow is True:
peer_port = 5553 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", session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="efgh",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=peer_port, 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: if slow is True:
session.rate_limiter.set_ul_limit(2**11) session.rate_limiter.set_ul_limit(2**11)
@ -783,6 +788,7 @@ class TestTransfer(TestCase):
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "client" db_dir = "client"
blob_dir = os.path.join(db_dir, "blobfiles") 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", self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, 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() self.stream_info_manager = TempEncryptedFileMetadataManager()
@ -870,13 +876,15 @@ class TestTransfer(TestCase):
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "client" db_dir = "client"
os.mkdir(db_dir) os.mkdir(db_dir)
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", 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_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) self.stream_info_manager = TempLiveStreamMetadataManager(hash_announcer)
@ -973,6 +981,7 @@ class TestTransfer(TestCase):
peer_finder = FakePeerFinder(5553, peer_manager, 2) peer_finder = FakePeerFinder(5553, peer_manager, 2)
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "client" db_dir = "client"
blob_dir = os.path.join(db_dir, "blobfiles") 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", self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, 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) d1 = self.wait_for_hash_from_queue(blob_hash_queue_1)
d2 = self.wait_for_hash_from_queue(blob_hash_queue_2) d2 = self.wait_for_hash_from_queue(blob_hash_queue_2)
@ -1051,6 +1060,7 @@ class TestTransfer(TestCase):
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
downloaders = [] downloaders = []
@ -1062,7 +1072,7 @@ class TestTransfer(TestCase):
self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd", self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, use_upnp=False, 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) self.stream_info_manager = DBEncryptedFileMetadataManager(self.session.db_dir)
@ -1169,6 +1179,7 @@ class TestTransfer(TestCase):
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "client" db_dir = "client"
blob_dir = os.path.join(db_dir, "blobfiles") 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", self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=None, peer_port=5553, 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() self.stream_info_manager = TempEncryptedFileMetadataManager()
@ -1287,6 +1298,7 @@ class TestStreamify(TestCase):
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "client" db_dir = "client"
blob_dir = os.path.join(db_dir, "blobfiles") 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", self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, 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() self.stream_info_manager = TempEncryptedFileMetadataManager()
@ -1339,6 +1351,7 @@ class TestStreamify(TestCase):
hash_announcer = FakeAnnouncer() hash_announcer = FakeAnnouncer()
rate_limiter = DummyRateLimiter() rate_limiter = DummyRateLimiter()
sd_identifier = StreamDescriptorIdentifier() sd_identifier = StreamDescriptorIdentifier()
blob_tracker = DummyBlobAvailabilityTracker()
db_dir = "client" db_dir = "client"
blob_dir = os.path.join(db_dir, "blobfiles") 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", self.session = Session(MIN_BLOB_DATA_PAYMENT_RATE, db_dir=db_dir, lbryid="abcd",
peer_finder=peer_finder, hash_announcer=hash_announcer, peer_finder=peer_finder, hash_announcer=hash_announcer,
blob_dir=blob_dir, peer_port=5553, 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) self.stream_info_manager = DBEncryptedFileMetadataManager(self.session.db_dir)

View file

@ -12,6 +12,8 @@ from lbrynet.core import PeerManager
from lbrynet.core import RateLimiter from lbrynet.core import RateLimiter
from lbrynet.core import Session from lbrynet.core import Session
from lbrynet.core import StreamDescriptor from lbrynet.core import StreamDescriptor
from lbrynet.core import BlobAvailability
from lbrynet.dht.node import Node
from lbrynet.lbryfile import EncryptedFileMetadataManager from lbrynet.lbryfile import EncryptedFileMetadataManager
from lbrynet.lbryfile.client import EncryptedFileOptions from lbrynet.lbryfile.client import EncryptedFileOptions
from lbrynet.lbryfilemanager import EncryptedFileCreator from lbrynet.lbryfilemanager import EncryptedFileCreator
@ -59,6 +61,7 @@ class TestReflector(unittest.TestCase):
hash_announcer = mocks.Announcer() hash_announcer = mocks.Announcer()
rate_limiter = RateLimiter.DummyRateLimiter() rate_limiter = RateLimiter.DummyRateLimiter()
sd_identifier = StreamDescriptor.StreamDescriptorIdentifier() sd_identifier = StreamDescriptor.StreamDescriptorIdentifier()
blob_tracker = BlobAvailability.DummyBlobAvailabilityTracker()
self.expected_blobs = [ self.expected_blobs = [
( (
@ -91,7 +94,9 @@ class TestReflector(unittest.TestCase):
peer_port=5553, peer_port=5553,
use_upnp=False, use_upnp=False,
rate_limiter=rate_limiter, rate_limiter=rate_limiter,
wallet=wallet wallet=wallet,
blob_tracker=blob_tracker,
dht_node_class=Node
) )
self.stream_info_manager = EncryptedFileMetadataManager.TempEncryptedFileMetadataManager() self.stream_info_manager = EncryptedFileMetadataManager.TempEncryptedFileMetadataManager()