fix tests

This commit is contained in:
Timothy Pogue 2022-12-02 12:28:27 -07:00
parent 49f6f40662
commit f1ebaf4730
2 changed files with 12 additions and 9 deletions

View File

@ -224,20 +224,21 @@ class ExternalMessageConsumer:
websockets.exceptions.InvalidMessage websockets.exceptions.InvalidMessage
) as e: ) as e:
logger.error(f"Connection Refused - {e} retrying in {self.sleep_time}s") logger.error(f"Connection Refused - {e} retrying in {self.sleep_time}s")
await asyncio.sleep(self.sleep_time)
continue
except ( except (
websockets.exceptions.ConnectionClosedError, websockets.exceptions.ConnectionClosedError,
websockets.exceptions.ConnectionClosedOK websockets.exceptions.ConnectionClosedOK
): ):
# Just keep trying to connect again indefinitely # Just keep trying to connect again indefinitely
pass await asyncio.sleep(self.sleep_time)
continue
except Exception as e: except Exception as e:
# An unforseen error has occurred, log and continue # An unforseen error has occurred, log and continue
logger.error("Unexpected error has occurred:") logger.error("Unexpected error has occurred:")
logger.exception(e) logger.exception(e)
finally:
await asyncio.sleep(self.sleep_time) await asyncio.sleep(self.sleep_time)
continue continue

View File

@ -94,7 +94,7 @@ def test_emc_handle_producer_message(patched_emc, caplog, ohlcv_history):
assert log_has( assert log_has(
f"Consumed message from `{producer_name}` of type `RPCMessageType.WHITELIST`", caplog) f"Consumed message from `{producer_name}` of type `RPCMessageType.WHITELIST`", caplog)
# Test handle analyzed_df message # Test handle analyzed_df single candle message
df_message = { df_message = {
"type": "analyzed_df", "type": "analyzed_df",
"data": { "data": {
@ -106,8 +106,7 @@ def test_emc_handle_producer_message(patched_emc, caplog, ohlcv_history):
patched_emc.handle_producer_message(test_producer, df_message) patched_emc.handle_producer_message(test_producer, df_message)
assert log_has(f"Received message of type `analyzed_df` from `{producer_name}`", caplog) assert log_has(f"Received message of type `analyzed_df` from `{producer_name}`", caplog)
assert log_has( assert log_has_re(r"Holes in data or no existing df,.+", caplog)
f"Consumed message from `{producer_name}` of type `RPCMessageType.ANALYZED_DF`", caplog)
# Test unhandled message # Test unhandled message
unhandled_message = {"type": "status", "data": "RUNNING"} unhandled_message = {"type": "status", "data": "RUNNING"}
@ -183,7 +182,7 @@ async def test_emc_create_connection_success(default_conf, caplog, mocker):
async with websockets.serve(eat, _TEST_WS_HOST, _TEST_WS_PORT): async with websockets.serve(eat, _TEST_WS_HOST, _TEST_WS_PORT):
await emc._create_connection(test_producer, lock) await emc._create_connection(test_producer, lock)
assert log_has_re(r"Producer connection success.+", caplog) assert log_has_re(r"Connected to channel.+", caplog)
finally: finally:
emc.shutdown() emc.shutdown()
@ -212,7 +211,8 @@ async def test_emc_create_connection_invalid_url(default_conf, caplog, mocker, h
dp = DataProvider(default_conf, None, None, None) dp = DataProvider(default_conf, None, None, None)
# Handle start explicitly to avoid messing with threading in tests # Handle start explicitly to avoid messing with threading in tests
mocker.patch("freqtrade.rpc.external_message_consumer.ExternalMessageConsumer.start",) mocker.patch("freqtrade.rpc.external_message_consumer.ExternalMessageConsumer.start")
mocker.patch("freqtrade.rpc.api_server.ws.channel.create_channel")
emc = ExternalMessageConsumer(default_conf, dp) emc = ExternalMessageConsumer(default_conf, dp)
try: try:
@ -390,6 +390,8 @@ async def test_emc_receive_messages_timeout(default_conf, caplog, mocker):
try: try:
change_running(emc) change_running(emc)
loop.call_soon(functools.partial(change_running, emc=emc)) loop.call_soon(functools.partial(change_running, emc=emc))
with pytest.raises(asyncio.TimeoutError):
await emc._receive_messages(TestChannel(), test_producer, lock) await emc._receive_messages(TestChannel(), test_producer, lock)
assert log_has_re(r"Ping error.+", caplog) assert log_has_re(r"Ping error.+", caplog)