mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
test: Improve test coverage of retry/fail logic
This commit is contained in:
parent
5112736385
commit
c04cf6c5cb
|
@ -662,7 +662,7 @@ class Exchange:
|
||||||
logger.debug("Performing scheduled market reload..")
|
logger.debug("Performing scheduled market reload..")
|
||||||
try:
|
try:
|
||||||
# on initial load, we retry 3 times to ensure we get the markets
|
# on initial load, we retry 3 times to ensure we get the markets
|
||||||
retries = 3 if force else 1
|
retries = 3 if force else 0
|
||||||
# Reload async markets, then assign them to sync api
|
# Reload async markets, then assign them to sync api
|
||||||
self._markets = retrier(self._load_async_markets, retries=retries)(reload=True)
|
self._markets = retrier(self._load_async_markets, retries=retries)(reload=True)
|
||||||
self._api.set_markets(self._api_async.markets, self._api_async.currencies)
|
self._api.set_markets(self._api_async.markets, self._api_async.currencies)
|
||||||
|
|
|
@ -638,6 +638,21 @@ def test_reload_markets(default_conf, mocker, caplog, time_machine):
|
||||||
exchange.reload_markets()
|
exchange.reload_markets()
|
||||||
assert lam_spy.call_count == 0
|
assert lam_spy.call_count == 0
|
||||||
|
|
||||||
|
# Another reload should happen but it fails.
|
||||||
|
time_machine.move_to(start_dt + timedelta(minutes=51), tick=False)
|
||||||
|
api_mock.load_markets = get_mock_coro(side_effect=ccxt.NetworkError("LoadError"))
|
||||||
|
|
||||||
|
exchange.reload_markets(force=False)
|
||||||
|
assert exchange.markets == updated_markets
|
||||||
|
assert lam_spy.call_count == 1
|
||||||
|
# Tried once, failed
|
||||||
|
|
||||||
|
lam_spy.reset_mock()
|
||||||
|
# When forceing (bot startup), it should retry 3 times.
|
||||||
|
exchange.reload_markets(force=True)
|
||||||
|
assert lam_spy.call_count == 4
|
||||||
|
assert exchange.markets == updated_markets
|
||||||
|
|
||||||
|
|
||||||
def test_reload_markets_exception(default_conf, mocker, caplog):
|
def test_reload_markets_exception(default_conf, mocker, caplog):
|
||||||
caplog.set_level(logging.DEBUG)
|
caplog.set_level(logging.DEBUG)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user