From 224896686fafeafb212f78259f50b4bfe85fb535 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Thu, 16 Jun 2022 14:39:19 -0400 Subject: [PATCH] Make FileManager.stop() async because SourceManager.stop() is now async. --- lbry/extras/daemon/components.py | 2 +- lbry/file/file_manager.py | 4 ++-- tests/integration/datanetwork/test_file_commands.py | 7 +++---- tests/integration/datanetwork/test_streaming.py | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lbry/extras/daemon/components.py b/lbry/extras/daemon/components.py index 5cce7d42c..96a47d07a 100644 --- a/lbry/extras/daemon/components.py +++ b/lbry/extras/daemon/components.py @@ -374,7 +374,7 @@ class FileManagerComponent(Component): log.info('Done setting up file manager') async def stop(self): - self.file_manager.stop() + await self.file_manager.stop() class BackgroundDownloaderComponent(Component): diff --git a/lbry/file/file_manager.py b/lbry/file/file_manager.py index c3ef9106c..14af863b5 100644 --- a/lbry/file/file_manager.py +++ b/lbry/file/file_manager.py @@ -50,10 +50,10 @@ class FileManager: await manager.started.wait() self.started.set() - def stop(self): + async def stop(self): for manager in self.source_managers.values(): # fixme: pop or not? - manager.stop() + await manager.stop() self.started.clear() @cache_concurrent diff --git a/tests/integration/datanetwork/test_file_commands.py b/tests/integration/datanetwork/test_file_commands.py index 95e92ce1e..60528b2da 100644 --- a/tests/integration/datanetwork/test_file_commands.py +++ b/tests/integration/datanetwork/test_file_commands.py @@ -354,7 +354,7 @@ class FileCommands(CommandTestCase): await self.daemon.jsonrpc_get('lbry://foo') with open(original_path, 'wb') as handle: handle.write(b'some other stuff was there instead') - self.daemon.file_manager.stop() + await self.daemon.file_manager.stop() await self.daemon.file_manager.start() await asyncio.wait_for(self.wait_files_to_complete(), timeout=5) # if this hangs, file didn't get set completed # check that internal state got through up to the file list API @@ -382,8 +382,7 @@ class FileCommands(CommandTestCase): resp = await self.out(self.daemon.jsonrpc_get('lbry://foo', timeout=2)) self.assertNotIn('error', resp) self.assertTrue(os.path.isfile(path)) - self.daemon.file_manager.stop() - await asyncio.sleep(0.01) # FIXME: this sleep should not be needed + await self.daemon.file_manager.stop() self.assertFalse(os.path.isfile(path)) async def test_incomplete_downloads_retry(self): @@ -478,7 +477,7 @@ class FileCommands(CommandTestCase): # restart the daemon and make sure the fee is still there - self.daemon.file_manager.stop() + await self.daemon.file_manager.stop() await self.daemon.file_manager.start() self.assertItemCount(await self.daemon.jsonrpc_file_list(), 1) self.assertEqual((await self.daemon.jsonrpc_file_list())['items'][0].content_fee.raw, raw_content_fee) diff --git a/tests/integration/datanetwork/test_streaming.py b/tests/integration/datanetwork/test_streaming.py index 4a61f08cc..fa9a7466b 100644 --- a/tests/integration/datanetwork/test_streaming.py +++ b/tests/integration/datanetwork/test_streaming.py @@ -21,7 +21,7 @@ def get_random_bytes(n: int) -> bytes: class RangeRequests(CommandTestCase): async def _restart_stream_manager(self): - self.daemon.file_manager.stop() + await self.daemon.file_manager.stop() await self.daemon.file_manager.start() return