fix tests

This commit is contained in:
Jack Robison 2019-05-05 19:41:35 -04:00
parent f506b3e6d4
commit b2f63a1545
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 16 additions and 12 deletions

View file

@ -1511,7 +1511,7 @@ class Daemon(metaclass=JSONRPCServerType):
raise Exception(f'Unable to find a file for {kwargs}')
stream = streams[0]
if status == 'start' and not stream.running:
await self.stream_manager.start_stream(stream)
await stream.save_file(node=self.stream_manager.node)
msg = "Resumed download"
elif status == 'stop' and stream.running:
await stream.stop()

View file

@ -5,7 +5,7 @@ import logging
import binascii
from aiohttp.web import Request, StreamResponse
from lbrynet.utils import generate_id
from lbrynet.error import DownloadSDTimeout, DownloadDataTimeout
from lbrynet.error import DownloadSDTimeout
from lbrynet.schema.mime_types import guess_media_type
from lbrynet.stream.downloader import StreamDownloader
from lbrynet.stream.descriptor import StreamDescriptor
@ -257,17 +257,11 @@ class ManagedStream:
return
log.info("start downloader for lbry://%s#%s (sd hash %s...)", self.claim_name, self.claim_id, self.sd_hash[:6])
self._running.set()
start_time = self.loop.time()
try:
await asyncio.wait_for(self.downloader.start(node), timeout, loop=self.loop)
if save_now:
await asyncio.wait_for(self.save_file(node=node), timeout - (self.loop.time() - start_time),
loop=self.loop)
except asyncio.TimeoutError:
self._running.clear()
if not self.descriptor:
raise DownloadSDTimeout(self.sd_hash)
raise DownloadDataTimeout(self.sd_hash)
raise DownloadSDTimeout(self.sd_hash)
if self.delayed_stop_task and not self.delayed_stop_task.done():
self.delayed_stop_task.cancel()

View file

@ -7,7 +7,7 @@ import random
from decimal import Decimal
from aiohttp.web import Request
from lbrynet.error import ResolveError, InvalidStreamDescriptorError, KeyFeeAboveMaxAllowed, InsufficientFundsError
from lbrynet.error import ResolveTimeout
from lbrynet.error import ResolveTimeout, DownloadDataTimeout
from lbrynet.utils import cache_concurrent
from lbrynet.stream.descriptor import StreamDescriptor
from lbrynet.stream.managed_stream import ManagedStream
@ -375,13 +375,23 @@ class StreamManager:
analytics_manager=self.analytics_manager
)
log.info("starting download for %s", uri)
await stream.start(self.node, timeout, save_now=save_file)
before_download = self.loop.time()
await stream.start(self.node, timeout)
stream.set_claim(resolved, claim)
if to_replace: # delete old stream now that the replacement has started downloading
await self.delete_stream(to_replace)
self.streams[stream.sd_hash] = stream
stream.set_claim(resolved, claim)
self.storage.content_claim_callbacks[stream.stream_hash] = lambda: self._update_content_claim(stream)
await self.storage.save_content_claim(stream.stream_hash, outpoint)
if save_file:
await asyncio.wait_for(stream.save_file(node=self.node), timeout - (self.loop.time() - before_download),
loop=self.loop)
return stream
except asyncio.TimeoutError:
error = DownloadDataTimeout(stream.sd_hash)
raise error
except Exception as err: # forgive data timeout, dont delete stream
error = err
raise