diff --git a/lbrynet/stream/assembler.py b/lbrynet/stream/assembler.py index a0de756ef..e7cf23c2b 100644 --- a/lbrynet/stream/assembler.py +++ b/lbrynet/stream/assembler.py @@ -113,8 +113,8 @@ class StreamAssembler: finally: if written_blobs == len(self.descriptor.blobs) - 2: log.debug("finished decrypting and assembling stream") - self.stream_finished_event.set() await self.after_finished() + self.stream_finished_event.set() else: log.debug("stream decryption and assembly did not finish (%i/%i blobs are done)", written_blobs or 0, len(self.descriptor.blobs) - 2) diff --git a/lbrynet/stream/stream_manager.py b/lbrynet/stream/stream_manager.py index 7edd3f8d1..e587b6e07 100644 --- a/lbrynet/stream/stream_manager.py +++ b/lbrynet/stream/stream_manager.py @@ -224,7 +224,6 @@ class StreamManager: try: await stream.downloader.stream_finished_event.wait() stream.update_status(ManagedStream.STATUS_FINISHED) - await self.storage.change_file_status(stream.stream_hash, ManagedStream.STATUS_FINISHED) except asyncio.CancelledError: pass task = self.loop.create_task(_wait_for_stream_finished()) diff --git a/tests/unit/stream/test_stream_manager.py b/tests/unit/stream/test_stream_manager.py index 6b567d70c..e8fa67670 100644 --- a/tests/unit/stream/test_stream_manager.py +++ b/tests/unit/stream/test_stream_manager.py @@ -96,11 +96,44 @@ class TestStreamManager(BlobExchangeTestBase): self.client_storage, get_mock_node(self.server_from_client)) self.exchange_rate_manager = get_dummy_exchange_rate_manager(time) - async def test_download_from_uri(self): + async def test_download_stop_resume_delete(self): self.assertSetEqual(self.stream_manager.streams, set()) stream = await self.stream_manager.download_stream_from_uri(self.uri, self.exchange_rate_manager) + stream_hash = stream.stream_hash + self.assertSetEqual(self.stream_manager.streams, {stream}) self.assertTrue(stream.running) self.assertFalse(stream.finished) + self.assertTrue(os.path.isfile(os.path.join(self.client_dir, "test_file"))) + stored_status = await self.client_storage.run_and_return_one_or_none( + "select status from file where stream_hash=?", stream_hash + ) + self.assertEqual(stored_status, "running") + + await self.stream_manager.stop_stream(stream) + + self.assertFalse(stream.finished) + self.assertFalse(stream.running) + self.assertFalse(os.path.isfile(os.path.join(self.client_dir, "test_file"))) + stored_status = await self.client_storage.run_and_return_one_or_none( + "select status from file where stream_hash=?", stream_hash + ) + self.assertEqual(stored_status, "stopped") + + await self.stream_manager.start_stream(stream) await stream.downloader.stream_finished_event.wait() + await asyncio.sleep(0.01) self.assertTrue(stream.finished) self.assertFalse(stream.running) + self.assertTrue(os.path.isfile(os.path.join(self.client_dir, "test_file"))) + stored_status = await self.client_storage.run_and_return_one_or_none( + "select status from file where stream_hash=?", stream_hash + ) + self.assertEqual(stored_status, "finished") + + await self.stream_manager.delete_stream(stream, True) + self.assertSetEqual(self.stream_manager.streams, set()) + self.assertFalse(os.path.isfile(os.path.join(self.client_dir, "test_file"))) + stored_status = await self.client_storage.run_and_return_one_or_none( + "select status from file where stream_hash=?", stream_hash + ) + self.assertEqual(stored_status, None)