mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
tests: add test for exchange_ws cleanup error
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import threading
|
import threading
|
||||||
|
from datetime import timedelta
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from unittest.mock import AsyncMock, MagicMock
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
|
|
||||||
from freqtrade.enums import CandleType
|
from freqtrade.enums import CandleType
|
||||||
from freqtrade.exchange.exchange_ws import ExchangeWS
|
from freqtrade.exchange.exchange_ws import ExchangeWS
|
||||||
|
from ft_client.test_client.test_rest_client import log_has_re
|
||||||
|
|
||||||
|
|
||||||
def test_exchangews_init(mocker):
|
def test_exchangews_init(mocker):
|
||||||
@@ -27,6 +29,23 @@ def test_exchangews_init(mocker):
|
|||||||
exchange_ws.cleanup()
|
exchange_ws.cleanup()
|
||||||
|
|
||||||
|
|
||||||
|
def test_exchangews_cleanup_error(mocker, caplog):
|
||||||
|
config = MagicMock()
|
||||||
|
ccxt_object = MagicMock()
|
||||||
|
ccxt_object.close = AsyncMock(side_effect=Exception("Test"))
|
||||||
|
mocker.patch("freqtrade.exchange.exchange_ws.ExchangeWS._start_forever", MagicMock())
|
||||||
|
|
||||||
|
exchange_ws = ExchangeWS(config, ccxt_object)
|
||||||
|
patch_eventloop_threading(exchange_ws)
|
||||||
|
|
||||||
|
sleep(0.1)
|
||||||
|
exchange_ws.reset_connections()
|
||||||
|
|
||||||
|
assert log_has_re("Exception in _cleanup_async", caplog)
|
||||||
|
|
||||||
|
exchange_ws.cleanup()
|
||||||
|
|
||||||
|
|
||||||
def patch_eventloop_threading(exchange):
|
def patch_eventloop_threading(exchange):
|
||||||
is_init = False
|
is_init = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user