download all blobs and check that on tests

This commit is contained in:
Victor Shyba 2021-10-15 03:23:45 -03:00
parent fcbe8cf00b
commit b1db42acf4
3 changed files with 8 additions and 1 deletions

View file

@ -17,6 +17,7 @@ from lbry.dht.blob_announcer import BlobAnnouncer
from lbry.blob.blob_manager import BlobManager from lbry.blob.blob_manager import BlobManager
from lbry.blob.disk_space_manager import DiskSpaceManager from lbry.blob.disk_space_manager import DiskSpaceManager
from lbry.blob_exchange.server import BlobServer from lbry.blob_exchange.server import BlobServer
from lbry.stream.managed_stream import ManagedStream
from lbry.stream.stream_manager import StreamManager from lbry.stream.stream_manager import StreamManager
from lbry.file.file_manager import FileManager from lbry.file.file_manager import FileManager
from lbry.extras.daemon.component import Component from lbry.extras.daemon.component import Component
@ -421,6 +422,8 @@ class BackgroundDownloader(Component):
stream = await file_manager.download_from_uri( stream = await file_manager.download_from_uri(
claim.permanent_url, None, 60.0, save_file=False, wallet=wallet claim.permanent_url, None, 60.0, save_file=False, wallet=wallet
) )
if isinstance(stream, ManagedStream):
await stream.save_blobs()
amount -= 1 amount -= 1
if amount == 0: if amount == 0:
break break

View file

@ -246,6 +246,10 @@ class ManagedStream(ManagedDownloadSource):
handle.write(data) handle.write(data)
handle.flush() handle.flush()
async def save_blobs(self):
async for _ in self._aiter_read_stream(0, connection_id=self.STREAMING_ID):
pass
async def _save_file(self, output_path: str): async def _save_file(self, output_path: str):
log.info("save file for lbry://%s#%s (sd hash %s...) -> %s", self.claim_name, self.claim_id, self.sd_hash[:6], log.info("save file for lbry://%s#%s (sd hash %s...) -> %s", self.claim_name, self.claim_id, self.sd_hash[:6],
output_path) output_path)

View file

@ -576,7 +576,7 @@ class DiskSpaceManagement(CommandTestCase):
class TestProactiveDownloaderComponent(CommandTestCase): class TestProactiveDownloaderComponent(CommandTestCase):
async def assertFileList(self, *txos): async def assertFileList(self, *txos):
txos_names = {txo['outputs'][0]['name'] for txo in txos} txos_names = {txo['outputs'][0]['name'] for txo in txos}
files = await self.file_list() files = await self.file_list(blobs_remaining=0)
self.assertEqual(len(txos), len(files)) self.assertEqual(len(txos), len(files))
file_claim_names = {file['claim_name'] for file in files} file_claim_names = {file['claim_name'] for file in files}
self.assertSetEqual(txos_names, file_claim_names) self.assertSetEqual(txos_names, file_claim_names)