fix more functional tests

This commit is contained in:
Jack 2016-10-03 16:37:27 -04:00
parent fd9bc6214a
commit 180d981ed8
3 changed files with 51 additions and 57 deletions

View file

@ -550,6 +550,9 @@ class Wallet(object):
d.addCallback(_decode) d.addCallback(_decode)
return d return d
def get_claim_metadata_for_sd_hash(self, sd_hash):
return self._get_claim_metadata_for_sd_hash(sd_hash)
def get_name_and_validity_for_sd_hash(self, sd_hash): def get_name_and_validity_for_sd_hash(self, sd_hash):
d = self._get_claim_metadata_for_sd_hash(sd_hash) d = self._get_claim_metadata_for_sd_hash(sd_hash)
d.addCallback(lambda name_txid: self._get_status_of_claim(name_txid[1], name_txid[0], sd_hash) if name_txid is not None else None) d.addCallback(lambda name_txid: self._get_status_of_claim(name_txid[1], name_txid[0], sd_hash) if name_txid is not None else None)

View file

@ -41,7 +41,7 @@ class ManagedEncryptedFileDownloader(EncryptedFileSaver):
def _save_sd_hash(sd_hash): def _save_sd_hash(sd_hash):
if len(sd_hash): if len(sd_hash):
self.sd_hash = sd_hash[0] self.sd_hash = sd_hash[0]
d = self.wallet._get_claim_metadata_for_sd_hash(self.sd_hash) d = self.wallet.get_claim_metadata_for_sd_hash(self.sd_hash)
else: else:
d = defer.succeed(None) d = defer.succeed(None)
@ -122,13 +122,12 @@ class ManagedEncryptedFileDownloader(EncryptedFileSaver):
def _start(self): def _start(self):
d = EncryptedFileSaver._start(self) d = EncryptedFileSaver._start(self)
d.addCallback(lambda _: self.stream_info_manager.get_sd_blob_hashes_for_stream(self.stream_hash))
d.addCallback(lambda _: self.stream_info_manager._get_sd_blob_hashes_for_stream(self.stream_hash))
def _save_sd_hash(sd_hash): def _save_sd_hash(sd_hash):
if len(sd_hash): if len(sd_hash):
self.sd_hash = sd_hash[0] self.sd_hash = sd_hash[0]
d = self.wallet._get_claim_metadata_for_sd_hash(self.sd_hash) d = self.wallet.get_claim_metadata_for_sd_hash(self.sd_hash)
else: else:
d = defer.succeed(None) d = defer.succeed(None)

View file

@ -28,10 +28,11 @@ from lbrynet.core.StreamDescriptor import download_sd_blob
from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file from lbrynet.lbryfilemanager.EncryptedFileCreator import create_lbry_file
from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier from lbrynet.lbryfile.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier
from lbrynet.lbryfile.StreamDescriptor import get_sd_info from lbrynet.lbryfile.StreamDescriptor import get_sd_info
from twisted.internet import defer, threads, task, error from twisted.internet import defer, threads, task
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.dht.node import Node
from lbrynet.core.BlobAvailability import DummyBlobAvailabilityTracker 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
@ -41,10 +42,6 @@ from lbrynet.core.server.ServerProtocol import ServerProtocolFactory
from lbrynet.lbrylive.server.LiveBlobInfoQueryHandler import CryptBlobInfoQueryHandlerFactory from lbrynet.lbrylive.server.LiveBlobInfoQueryHandler import CryptBlobInfoQueryHandlerFactory
from lbrynet.lbrylive.client.LiveStreamOptions import add_live_stream_to_sd_identifier from lbrynet.lbrylive.client.LiveStreamOptions import add_live_stream_to_sd_identifier
from lbrynet.lbrylive.client.LiveStreamDownloader import add_full_live_stream_downloader_to_sd_identifier from lbrynet.lbrylive.client.LiveStreamDownloader import add_full_live_stream_downloader_to_sd_identifier
from lbrynet.core.BlobManager import TempBlobManager
from lbrynet.reflector.client.client import EncryptedFileReflectorClientFactory
from lbrynet.reflector.server.server import ReflectorServerFactory
from lbrynet.lbryfile.StreamDescriptor import publish_sd_blob
log_format = "%(funcName)s(): %(message)s" log_format = "%(funcName)s(): %(message)s"
@ -106,6 +103,9 @@ class FakeWallet(object):
def set_public_key_for_peer(self, peer, public_key): def set_public_key_for_peer(self, peer, public_key):
pass pass
def get_claim_metadata_for_sd_hash(self, sd_hash):
return "fakeuri", "faketxid"
class FakePeerFinder(object): class FakePeerFinder(object):
def __init__(self, start_port, peer_manager, num_peers): def __init__(self, start_port, peer_manager, num_peers):
@ -212,15 +212,11 @@ test_create_stream_sd_file = {
def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rate_limit=None): def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rate_limit=None):
if sys.platform.startswith("linux"):
sys.modules = sys.modules.copy() sys.modules = sys.modules.copy()
del sys.modules['twisted.internet.reactor'] del sys.modules['twisted.internet.reactor']
import twisted.internet import twisted.internet
twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor() twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor()
sys.modules['twisted.internet.reactor'] = twisted.internet.reactor sys.modules['twisted.internet.reactor'] = twisted.internet.reactor
from twisted.internet import reactor from twisted.internet import reactor
@ -245,7 +241,8 @@ def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rat
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, blob_tracker=blob_tracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker,
dht_node_class=Node)
stream_info_manager = TempEncryptedFileMetadataManager() stream_info_manager = TempEncryptedFileMetadataManager()
@ -323,19 +320,17 @@ def start_lbry_uploader(sd_hash_queue, kill_event, dead_event, file_size, ul_rat
sd_hash_queue.put(sd_hash) sd_hash_queue.put(sd_hash)
reactor.callLater(1, start_all) reactor.callLater(1, start_all)
if not reactor.running:
reactor.run() reactor.run()
def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_rate_limit=None): def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_rate_limit=None):
if sys.platform.startswith("linux"):
sys.modules = sys.modules.copy() sys.modules = sys.modules.copy()
del sys.modules['twisted.internet.reactor'] del sys.modules['twisted.internet.reactor']
import twisted.internet import twisted.internet
twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor() twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor()
sys.modules['twisted.internet.reactor'] = twisted.internet.reactor sys.modules['twisted.internet.reactor'] = twisted.internet.reactor
from twisted.internet import reactor from twisted.internet import reactor
@ -440,20 +435,17 @@ def start_lbry_reuploader(sd_hash, kill_event, dead_event, ready_event, n, ul_ra
d = task.deferLater(reactor, 1.0, start_transfer) d = task.deferLater(reactor, 1.0, start_transfer)
d.addCallback(lambda _: start_server()) d.addCallback(lambda _: start_server())
if not reactor.running:
reactor.run() reactor.run()
def start_live_server(sd_hash_queue, kill_event, dead_event): def start_live_server(sd_hash_queue, kill_event, dead_event):
if sys.platform.startswith("linux"):
sys.modules = sys.modules.copy() sys.modules = sys.modules.copy()
del sys.modules['twisted.internet.reactor'] del sys.modules['twisted.internet.reactor']
import twisted.internet import twisted.internet
twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor() twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor()
sys.modules['twisted.internet.reactor'] = twisted.internet.reactor sys.modules['twisted.internet.reactor'] = twisted.internet.reactor
from twisted.internet import reactor from twisted.internet import reactor
@ -584,19 +576,17 @@ def start_live_server(sd_hash_queue, kill_event, dead_event):
return d return d
reactor.callLater(1, run_server) reactor.callLater(1, run_server)
if not reactor.running:
reactor.run() reactor.run()
def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow): def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow):
if sys.platform.startswith("linux"):
sys.modules = sys.modules.copy() sys.modules = sys.modules.copy()
del sys.modules['twisted.internet.reactor'] del sys.modules['twisted.internet.reactor']
import twisted.internet import twisted.internet
twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor() twisted.internet.reactor = twisted.internet.epollreactor.EPollReactor()
sys.modules['twisted.internet.reactor'] = twisted.internet.reactor sys.modules['twisted.internet.reactor'] = twisted.internet.reactor
from twisted.internet import reactor from twisted.internet import reactor
@ -689,6 +679,7 @@ def start_blob_uploader(blob_hash_queue, kill_event, dead_event, slow):
logging.debug("blob hash has been added to the queue") logging.debug("blob hash has been added to the queue")
reactor.callLater(1, start_all) reactor.callLater(1, start_all)
if not reactor.running:
reactor.run() reactor.run()
@ -771,7 +762,7 @@ class TestTransfer(TestCase):
return d return d
@unittest.skip("Sadly skipping failing test instead of fixing it") # @unittest.skip("Sadly skipping failing test instead of fixing it")
def test_lbry_transfer(self): def test_lbry_transfer(self):
sd_hash_queue = Queue() sd_hash_queue = Queue()
kill_event = Event() kill_event = Event()
@ -798,7 +789,8 @@ 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, blob_tracker=blob_tracker) use_upnp=False, rate_limiter=rate_limiter, wallet=wallet, blob_tracker=blob_tracker,
dht_node_class=Node)
self.stream_info_manager = TempEncryptedFileMetadataManager() self.stream_info_manager = TempEncryptedFileMetadataManager()
@ -884,7 +876,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, 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) blob_tracker=blob_tracker, dht_node_class=Node)
self.stream_info_manager = TempLiveStreamMetadataManager(hash_announcer) self.stream_info_manager = TempLiveStreamMetadataManager(hash_announcer)
@ -957,7 +949,7 @@ class TestTransfer(TestCase):
d.addBoth(stop) d.addBoth(stop)
return d return d
@require_system('Linux') # @require_system('Linux')
def test_last_blob_retrieval(self): def test_last_blob_retrieval(self):
kill_event = Event() kill_event = Event()
@ -1043,7 +1035,7 @@ class TestTransfer(TestCase):
return d return d
@unittest.skip("Sadly skipping failing test instead of fixing it") # @unittest.skip("Sadly skipping failing test instead of fixing it")
def test_double_download(self): def test_double_download(self):
sd_hash_queue = Queue() sd_hash_queue = Queue()
kill_event = Event() kill_event = Event()