From c04cf6c5cb48a7071b395e48d0a401c1d269cac7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 13 Sep 2024 07:23:46 +0200 Subject: [PATCH] test: Improve test coverage of retry/fail logic --- freqtrade/exchange/exchange.py | 2 +- tests/exchange/test_exchange.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 0b73cd6e6..30c2aae6d 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -662,7 +662,7 @@ class Exchange: logger.debug("Performing scheduled market reload..") try: # 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 self._markets = retrier(self._load_async_markets, retries=retries)(reload=True) self._api.set_markets(self._api_async.markets, self._api_async.currencies) diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 212c65e54..35cc82db1 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -638,6 +638,21 @@ def test_reload_markets(default_conf, mocker, caplog, time_machine): exchange.reload_markets() 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): caplog.set_level(logging.DEBUG)