From 0052e5891788ffbfdaf20dd0374599924369644e Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 12 Sep 2022 19:50:22 +0200 Subject: [PATCH] emc: Fix potential startup timing issue --- freqtrade/rpc/external_message_consumer.py | 6 +++--- tests/rpc/test_rpc_emc.py | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/freqtrade/rpc/external_message_consumer.py b/freqtrade/rpc/external_message_consumer.py index 59064c90b..122863987 100644 --- a/freqtrade/rpc/external_message_consumer.py +++ b/freqtrade/rpc/external_message_consumer.py @@ -15,6 +15,7 @@ from pydantic import ValidationError from freqtrade.data.dataprovider import DataProvider from freqtrade.enums import RPCMessageType +from freqtrade.exceptions import OperationalException from freqtrade.misc import remove_entry_exit_signals from freqtrade.rpc.api_server.ws.channel import WebSocketChannel from freqtrade.rpc.api_server.ws_schemas import (WSAnalyzedDFMessage, WSAnalyzedDFRequest, @@ -57,7 +58,7 @@ class ExternalMessageConsumer: self.producers = self._emc_config.get('producers', []) if self.enabled and len(self.producers) < 1: - raise ValueError("You must specify at least 1 Producer to connect to.") + raise OperationalException("You must specify at least 1 Producer to connect to.") self.wait_timeout = self._emc_config.get('wait_timeout', 300) # in seconds self.ping_timeout = self._emc_config.get('ping_timeout', 10) # in seconds @@ -97,9 +98,8 @@ class ExternalMessageConsumer: self._loop = asyncio.new_event_loop() self._thread = Thread(target=self._loop.run_forever) - self._thread.start() - self._running = True + self._thread.start() self._main_task = asyncio.run_coroutine_threadsafe(self._main(), loop=self._loop) diff --git a/tests/rpc/test_rpc_emc.py b/tests/rpc/test_rpc_emc.py index b3f6fdc4d..94635810c 100644 --- a/tests/rpc/test_rpc_emc.py +++ b/tests/rpc/test_rpc_emc.py @@ -11,6 +11,7 @@ import pytest import websockets from freqtrade.data.dataprovider import DataProvider +from freqtrade.exceptions import OperationalException from freqtrade.rpc.external_message_consumer import ExternalMessageConsumer from tests.conftest import log_has, log_has_re, log_has_when @@ -71,7 +72,7 @@ def test_emc_shutdown(patched_emc, caplog): assert not log_has("Stopping ExternalMessageConsumer", caplog) -def test_emc_init(patched_emc, default_conf, mocker, caplog): +def test_emc_init(patched_emc, default_conf): # Test the settings were set correctly assert patched_emc.initial_candle_limit <= 1500 assert patched_emc.wait_timeout > 0 @@ -84,12 +85,10 @@ def test_emc_init(patched_emc, default_conf, mocker, caplog): } }) dataprovider = DataProvider(default_conf, None, None, None) - with pytest.raises(ValueError) as exc: + with pytest.raises(OperationalException, + match="You must specify at least 1 Producer to connect to."): ExternalMessageConsumer(default_conf, dataprovider) - # Make sure we failed because of no producers - assert str(exc.value) == "You must specify at least 1 Producer to connect to." - # Parametrize this? def test_emc_handle_producer_message(patched_emc, caplog, ohlcv_history):