minor test fixes

This commit is contained in:
Lex Berezhny 2019-01-07 14:27:21 -05:00
parent 26a3221bac
commit 3fdcb80960
6 changed files with 12 additions and 19 deletions

View file

@ -168,16 +168,12 @@ class EncryptedFileSaver(EncryptedFileDownloader):
def _close_output(self): def _close_output(self):
self.file_handle, file_handle = None, self.file_handle self.file_handle, file_handle = None, self.file_handle
#def close_file():
if file_handle is not None: if file_handle is not None:
name = file_handle.name name = file_handle.name
file_handle.close() file_handle.close()
if self.completed is False: if self.completed is False:
os.remove(name) os.remove(name)
#return threads.deferToThread(close_file)
def _get_write_func(self): def _get_write_func(self):
def write_func(data): def write_func(data):
if self.stopped is False and self.file_handle is not None: if self.stopped is False and self.file_handle is not None:

View file

@ -19,8 +19,7 @@ class EncryptedFileMetadataHandler:
@defer.inlineCallbacks @defer.inlineCallbacks
def get_initial_blobs(self): def get_initial_blobs(self):
blob_infos = yield f2d(self.storage.get_blobs_for_stream(self.stream_hash)) blob_infos = yield f2d(self.storage.get_blobs_for_stream(self.stream_hash))
formatted_infos = self._format_initial_blobs_for_download_manager(blob_infos) return self._format_initial_blobs_for_download_manager(blob_infos)
defer.returnValue(formatted_infos)
def final_blob_num(self): def final_blob_num(self):
return self._final_blob_num return self._final_blob_num

View file

@ -57,7 +57,7 @@ def start_daemon(settings: typing.Optional[typing.Dict] = None,
if check_connection(): if check_connection():
daemon = Daemon() daemon = Daemon()
asyncio.get_event_loop().create_task(daemon.start_listening()) asyncio.create_task(daemon.start_listening())
reactor.run() reactor.run()
else: else:
log.info("Not connected to internet, unable to start") log.info("Not connected to internet, unable to start")

View file

@ -30,7 +30,7 @@ class DownloadManager:
def resume_downloading(self): def resume_downloading(self):
yield self.connection_manager.start() yield self.connection_manager.start()
yield self.progress_manager.start() yield self.progress_manager.start()
defer.returnValue(True) return True
@defer.inlineCallbacks @defer.inlineCallbacks
def stop_downloading(self): def stop_downloading(self):
@ -40,18 +40,13 @@ class DownloadManager:
def add_blobs_to_download(self, blob_infos): def add_blobs_to_download(self, blob_infos):
log.debug("Adding %s blobs to blobs", len(blob_infos)) log.debug("Adding %s blobs to blobs", len(blob_infos))
def add_blob_to_list(blob, blob_num):
self.blobs[blob_num] = blob
log.debug(
"Added blob (hash: %s, number %s) to the list", blob.blob_hash, blob_num)
for blob_info in blob_infos: for blob_info in blob_infos:
if not blob_info.blob_num in self.blobs: if not blob_info.blob_num in self.blobs:
self.blob_infos[blob_info.blob_num] = blob_info self.blob_infos[blob_info.blob_num] = blob_info
log.debug( log.debug("Trying to get the blob associated with blob hash %s", blob_info.blob_hash)
"Trying to get the blob associated with blob hash %s", blob_info.blob_hash)
blob = self.blob_manager.get_blob(blob_info.blob_hash, blob_info.length) blob = self.blob_manager.get_blob(blob_info.blob_hash, blob_info.length)
add_blob_to_list(blob, blob_info.blob_num) self.blobs[blob_info.blob_num] = blob
log.debug("Added blob (hash: %s, number %s) to the list", blob.blob_hash, blob_info.blob_num)
def stream_position(self): def stream_position(self):
return self.progress_manager.stream_position() return self.progress_manager.stream_position()

View file

@ -105,7 +105,7 @@ class LbryUploader:
for lbry_file in lbry_files: for lbry_file in lbry_files:
yield self.lbry_file_manager.delete_lbry_file(lbry_file) yield self.lbry_file_manager.delete_lbry_file(lbry_file)
yield self.lbry_file_manager.stop() yield self.lbry_file_manager.stop()
yield self.blob_manager.stop() yield f2d(self.blob_manager.stop())
yield f2d(self.storage.close()) yield f2d(self.storage.close())
self.server_port.stopListening() self.server_port.stopListening()
rm_db_and_blob_dir(self.db_dir, self.blob_dir) rm_db_and_blob_dir(self.db_dir, self.blob_dir)
@ -115,6 +115,7 @@ class LbryUploader:
@skip @skip
class TestTransfer(unittest.TestCase): class TestTransfer(unittest.TestCase):
@defer.inlineCallbacks @defer.inlineCallbacks
def setUp(self): def setUp(self):
mocks.mock_conf_settings(self) mocks.mock_conf_settings(self)

View file

@ -238,10 +238,11 @@ class StreamStorageTests(StorageTest):
class FileStorageTests(StorageTest): class FileStorageTests(StorageTest):
async def test_setup_output(self): @defer.inlineCallbacks
def test_setup_output(self):
file_name = 'encrypted_file_saver_test.tmp' file_name = 'encrypted_file_saver_test.tmp'
self.assertFalse(os.path.isfile(file_name)) self.assertFalse(os.path.isfile(file_name))
written_to = await open_file_for_writing(self.db_dir, file_name) written_to = yield f2d(open_file_for_writing(self.db_dir, file_name))
self.assertEqual(written_to, file_name) self.assertEqual(written_to, file_name)
self.assertTrue(os.path.isfile(os.path.join(self.db_dir, file_name))) self.assertTrue(os.path.isfile(os.path.join(self.db_dir, file_name)))
@ -285,6 +286,7 @@ class FileStorageTests(StorageTest):
class ContentClaimStorageTests(StorageTest): class ContentClaimStorageTests(StorageTest):
@defer.inlineCallbacks @defer.inlineCallbacks
def test_store_content_claim(self): def test_store_content_claim(self):
download_directory = self.db_dir download_directory = self.db_dir