tests resuming downloads with conflicting file names

This commit is contained in:
Victor Shyba 2019-02-13 20:40:14 -03:00 committed by Lex Berezhny
parent 37bb765a2e
commit 3fce8e4023

View file

@ -1,5 +1,8 @@
import asyncio
import logging import logging
from integration.testcase import CommandTestCase import os
from .testcase import CommandTestCase
class FileCommands(CommandTestCase): class FileCommands(CommandTestCase):
@ -38,3 +41,29 @@ class FileCommands(CommandTestCase):
resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2) resp = await self.daemon.jsonrpc_get('lbry://foo', timeout=2)
self.assertIn('error', resp) self.assertIn('error', resp)
self.assertEquals('Failed to download sd blob %s within timeout' % sd_hash, resp['error']) self.assertEquals('Failed to download sd blob %s within timeout' % sd_hash, resp['error'])
async def wait_files_to_complete(self):
while self.daemon.jsonrpc_file_list(status='running'):
print(self.daemon.jsonrpc_file_list())
await asyncio.sleep(0.01)
async def test_filename_conflicts_management_on_resume_download(self):
await self.make_claim('foo', '0.01', data=bytes([0]*(1<<23)))
file_info = self.daemon.jsonrpc_file_list()[0]
original_path = os.path.join(self.daemon.conf.download_dir, file_info['file_name'])
await self.daemon.jsonrpc_file_delete(claim_name='foo')
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.stream_manager.stop()
await self.daemon.stream_manager.start()
await asyncio.wait_for(self.wait_files_to_complete(), timeout=5) # if this hangs, file didnt get set completed
# check that internal state got through up to the file list API
downloader = self.daemon.stream_manager.get_stream_by_stream_hash(file_info['stream_hash']).downloader
file_info = self.daemon.jsonrpc_file_list()[0]
self.assertEqual(downloader.output_file_name, file_info['file_name'])
# checks if what the API shows is what he have at the very internal level.
self.assertEqual(downloader.output_path, file_info['download_path'])
# 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