From 60ba07cc1700fa9a8f04cc351156651e674b9f90 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 13 Feb 2019 21:30:59 -0300 Subject: [PATCH] add tests for incomplete files, update existing one --- tests/integration/test_file_commands.py | 16 ++++++++++++++++ tests/unit/stream/test_assembler.py | 7 +++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_file_commands.py b/tests/integration/test_file_commands.py index fa3091bb5..a8800fd25 100644 --- a/tests/integration/test_file_commands.py +++ b/tests/integration/test_file_commands.py @@ -66,3 +66,19 @@ class FileCommands(CommandTestCase): # if you got here refactoring just change above, but ensure what gets set internally gets reflected externally! self.assertTrue(downloader.output_path.endswith(downloader.output_file_name)) # this used to be inconsistent, if it becomes again it would create weird bugs, so worth checking + + async def test_incomplete_downloads_erases_output_file_on_stop(self): + claim = await self.make_claim('foo', '0.01') + sd_hash = claim['output']['value']['stream']['source']['source'] + await self.daemon.jsonrpc_file_delete(claim_name='foo') + all_except_sd = [ + blob_hash for blob_hash in self.server.blob_manager.completed_blob_hashes if blob_hash != sd_hash + ] + await self.server.blob_manager.delete_blobs(all_except_sd) + + resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2) + self.assertIn('error', resp) + file_info = self.daemon.jsonrpc_file_list()[0] + self.assertTrue(os.path.isfile(os.path.join(file_info['download_path']))) + await self.daemon.jsonrpc_file_set_status('stop', sd_hash=sd_hash) + self.assertFalse(os.path.isfile(os.path.join(file_info['download_path']))) diff --git a/tests/unit/stream/test_assembler.py b/tests/unit/stream/test_assembler.py index 2d7d15a63..ef636890f 100644 --- a/tests/unit/stream/test_assembler.py +++ b/tests/unit/stream/test_assembler.py @@ -57,11 +57,11 @@ class TestStreamAssembler(AsyncioTestCase): # assemble the decrypted file assembler = StreamAssembler(self.loop, downloader_blob_manager, descriptor.sd_hash) await assembler.assemble_decrypted_stream(download_dir) + if corrupt: + return self.assertFalse(os.path.isfile(os.path.join(download_dir, "test_file"))) with open(os.path.join(download_dir, "test_file"), "rb") as f: decrypted = f.read() - if corrupt: - return decrypted self.assertEqual(decrypted, self.cleartext) self.assertEqual(True, self.blob_manager.get_blob(sd_hash).get_is_verified()) self.assertEqual(True, self.blob_manager.get_blob(descriptor.blobs[0].blob_hash).get_is_verified()) @@ -113,6 +113,5 @@ class TestStreamAssembler(AsyncioTestCase): async def test_create_truncate_and_handle_stream(self): self.cleartext = b'potato' * 1337 * 5279 - decrypted = await self.test_create_and_decrypt_one_blob_stream(corrupt=True) # The purpose of this test is just to make sure it can finish even if a blob is corrupt/truncated - self.assertFalse(decrypted) + await asyncio.wait_for(self.test_create_and_decrypt_one_blob_stream(corrupt=True), timeout=5)