forked from LBRYCommunity/lbry-sdk
don't fail when a single one go on maintenance and set completion event regardless of failures
This commit is contained in:
parent
dabb168853
commit
3c67bb90d7
2 changed files with 27 additions and 5 deletions
|
@ -79,7 +79,6 @@ class MarketFeed:
|
|||
log.debug("Saving rate update %f for %s from %s", rate, self.market, self.name)
|
||||
self.rate = ExchangeRate(self.market, rate, int(time.time()))
|
||||
self.last_check = time.time()
|
||||
self.event.set()
|
||||
return self.rate
|
||||
except asyncio.CancelledError:
|
||||
raise
|
||||
|
@ -95,6 +94,8 @@ class MarketFeed:
|
|||
log.warning("Error trying to connect to exchange rate %s: %s", self.name, str(e))
|
||||
except Exception as e:
|
||||
log.exception("Exchange rate error (%s from %s):", self.market, self.name)
|
||||
finally:
|
||||
self.event.set()
|
||||
|
||||
async def keep_updated(self):
|
||||
while True:
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import asyncio
|
||||
import logging
|
||||
from decimal import Decimal
|
||||
from lbry.testcase import AsyncioTestCase
|
||||
from lbry.extras.daemon.exchange_rate_manager import ExchangeRate, ExchangeRateManager, FEEDS
|
||||
from lbry.extras.daemon.exchange_rate_manager import ExchangeRate, ExchangeRateManager, FEEDS, MarketFeed
|
||||
|
||||
|
||||
class TestExchangeRateManager(AsyncioTestCase):
|
||||
|
@ -12,13 +14,32 @@ class TestExchangeRateManager(AsyncioTestCase):
|
|||
self.assertFalse(feed.is_online)
|
||||
self.assertIsNone(feed.rate)
|
||||
await manager.wait()
|
||||
failures = set()
|
||||
for feed in manager.market_feeds:
|
||||
self.assertTrue(feed.is_online)
|
||||
if feed.is_online:
|
||||
self.assertIsInstance(feed.rate, ExchangeRate)
|
||||
# print(f'{feed.name} - {feed.market} - {feed.rate.spot}')
|
||||
else:
|
||||
failures.add(feed.name)
|
||||
self.assertFalse(feed.has_rate)
|
||||
self.assertLessEqual(len(failures), 1, f"feed failures: {failures}. Please check exchange rate feeds!")
|
||||
lbc = manager.convert_currency('USD', 'LBC', Decimal('1.0'))
|
||||
self.assertGreaterEqual(lbc, 2.0)
|
||||
self.assertLessEqual(lbc, 10.0)
|
||||
lbc = manager.convert_currency('BTC', 'LBC', Decimal('0.01'))
|
||||
self.assertGreaterEqual(lbc, 1_000)
|
||||
self.assertLessEqual(lbc, 4_000)
|
||||
|
||||
async def test_it_handles_feed_being_offline(self):
|
||||
class FakeFeed(MarketFeed):
|
||||
name = "fake"
|
||||
url = "http://impossi.bru"
|
||||
manager = ExchangeRateManager((FakeFeed,))
|
||||
manager.start()
|
||||
self.addCleanup(manager.stop)
|
||||
for feed in manager.market_feeds:
|
||||
self.assertFalse(feed.is_online)
|
||||
self.assertIsNone(feed.rate)
|
||||
await asyncio.wait_for(manager.wait(), 2)
|
||||
for feed in manager.market_feeds:
|
||||
self.assertFalse(feed.is_online)
|
||||
self.assertFalse(feed.has_rate)
|
||||
|
|
Loading…
Reference in a new issue