add tests for incomplete files, update existing one
This commit is contained in:
parent
dbc8cfe5ae
commit
60ba07cc17
2 changed files with 19 additions and 4 deletions
|
@ -66,3 +66,19 @@ class FileCommands(CommandTestCase):
|
||||||
# if you got here refactoring just change above, but ensure what gets set internally gets reflected externally!
|
# 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))
|
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
|
# 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'])))
|
||||||
|
|
|
@ -57,11 +57,11 @@ class TestStreamAssembler(AsyncioTestCase):
|
||||||
# assemble the decrypted file
|
# assemble the decrypted file
|
||||||
assembler = StreamAssembler(self.loop, downloader_blob_manager, descriptor.sd_hash)
|
assembler = StreamAssembler(self.loop, downloader_blob_manager, descriptor.sd_hash)
|
||||||
await assembler.assemble_decrypted_stream(download_dir)
|
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:
|
with open(os.path.join(download_dir, "test_file"), "rb") as f:
|
||||||
decrypted = f.read()
|
decrypted = f.read()
|
||||||
if corrupt:
|
|
||||||
return decrypted
|
|
||||||
self.assertEqual(decrypted, self.cleartext)
|
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(sd_hash).get_is_verified())
|
||||||
self.assertEqual(True, self.blob_manager.get_blob(descriptor.blobs[0].blob_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):
|
async def test_create_truncate_and_handle_stream(self):
|
||||||
self.cleartext = b'potato' * 1337 * 5279
|
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
|
# 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)
|
||||||
|
|
Loading…
Reference in a new issue