From 9cf613955775fdf0b27e5e7497b647b48be907d7 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Fri, 15 Oct 2021 03:39:36 -0300 Subject: [PATCH] fix and test main api --- lbry/extras/daemon/components.py | 10 ++++++---- .../integration/datanetwork/test_file_commands.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index c27cb3e09..e9fdb0573 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -388,6 +388,7 @@ class BackgroundDownloader(Component): self.status = {'pending': 0, 'ongoing': 0} self.task: typing.Optional[asyncio.Task] = None self.download_loop_delay_seconds = 60 + self.finished_iteration = asyncio.Event() @property def component(self) -> 'BackgroundDownloader': @@ -398,7 +399,6 @@ class BackgroundDownloader(Component): return self.status async def loop(self): - return db: SQLiteStorage = self.component_manager.get_component(DATABASE_COMPONENT) while True: for channel_id, download_latest, download_all in await db.get_subscriptions(): @@ -406,6 +406,8 @@ class BackgroundDownloader(Component): if not amount: continue await self.ensure_download(channel_id, amount) + self.finished_iteration.set() + self.finished_iteration.clear() await asyncio.sleep(self.download_loop_delay_seconds) async def ensure_download(self, channel_id, amount): @@ -414,9 +416,10 @@ class BackgroundDownloader(Component): ledger = wallet.ledger claims, _, _, _ = await ledger.claim_search( ledger.accounts, channel_id=channel_id, order_by=['release_time', '^height']) - page = 0 + offset = 0 while claims and amount > 0: for claim in claims: + offset += 1 if not claim.script.source or claim.has_price: continue stream = await file_manager.download_from_uri( @@ -427,9 +430,8 @@ class BackgroundDownloader(Component): amount -= 1 if amount == 0: break - page += 1 claims, _, _, _ = await ledger.claim_search( - ledger.accounts, channel_id=channel_id, order_by=['release_time', '^height'], page=page) + ledger.accounts, channel_id=channel_id, order_by=['release_time', '^height'], offset=offset) async def start(self): self.task = asyncio.create_task(self.loop()) diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index c8d333cf1..4f8108163 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -603,3 +603,18 @@ class TestProactiveDownloaderComponent(CommandTestCase): # ignores reposts await proactive_downloader.ensure_download(channel_id, 4) await self.assertFileList(content1, content2) + + await self.daemon.jsonrpc_file_delete(delete_all=True) + self.assertEqual(0, len(await self.file_list())) + await proactive_downloader.stop() + await self.daemon.jsonrpc_channel_subscribe(channel_id, 1) + await proactive_downloader.start() + await proactive_downloader.finished_iteration.wait() + await self.assertFileList(content1) + await self.daemon.jsonrpc_file_delete(delete_all=True) + + await self.daemon.jsonrpc_channel_subscribe(channel_id, download_all=True) + await proactive_downloader.stop() + await proactive_downloader.start() + await proactive_downloader.finished_iteration.wait() + await self.assertFileList(content1, content2)