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):
self.file_handle, file_handle = None, self.file_handle
#def close_file():
if file_handle is not None:
name = file_handle.name
file_handle.close()
if self.completed is False:
os.remove(name)
#return threads.deferToThread(close_file)
def _get_write_func(self):
def write_func(data):
if self.stopped is False and self.file_handle is not None:

View file

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

View file

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

View file

@ -30,7 +30,7 @@ class DownloadManager:
def resume_downloading(self):
yield self.connection_manager.start()
yield self.progress_manager.start()
defer.returnValue(True)
return True
@defer.inlineCallbacks
def stop_downloading(self):
@ -40,18 +40,13 @@ class DownloadManager:
def add_blobs_to_download(self, 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:
if not blob_info.blob_num in self.blobs:
self.blob_infos[blob_info.blob_num] = blob_info
log.debug(
"Trying to get the blob associated with blob hash %s", blob_info.blob_hash)
log.debug("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)
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):
return self.progress_manager.stream_position()

View file

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

View file

@ -238,10 +238,11 @@ class StreamStorageTests(StorageTest):
class FileStorageTests(StorageTest):
async def test_setup_output(self):
@defer.inlineCallbacks
def test_setup_output(self):
file_name = 'encrypted_file_saver_test.tmp'
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.assertTrue(os.path.isfile(os.path.join(self.db_dir, file_name)))
@ -285,6 +286,7 @@ class FileStorageTests(StorageTest):
class ContentClaimStorageTests(StorageTest):
@defer.inlineCallbacks
def test_store_content_claim(self):
download_directory = self.db_dir