diff --git a/src/ert/ensemble_evaluator/evaluator.py b/src/ert/ensemble_evaluator/evaluator.py index 4afe8e97971..90615c387c2 100644 --- a/src/ert/ensemble_evaluator/evaluator.py +++ b/src/ert/ensemble_evaluator/evaluator.py @@ -260,7 +260,7 @@ async def handle_dispatch(self, websocket: WebSocketServerProtocol) -> None: f"closing connection to dispatcher: {ex}" ) await websocket.close( - code=1011, reason=f"failed handling {event}" + code=1011, reason=f"failed handling message {raw_msg!r}" ) return diff --git a/tests/unit_tests/ensemble_evaluator/test_ensemble_evaluator.py b/tests/unit_tests/ensemble_evaluator/test_ensemble_evaluator.py index 668527b6017..1b418d2bef5 100644 --- a/tests/unit_tests/ensemble_evaluator/test_ensemble_evaluator.py +++ b/tests/unit_tests/ensemble_evaluator/test_ensemble_evaluator.py @@ -2,10 +2,12 @@ import datetime from functools import partial from typing import cast +from unittest.mock import MagicMock import pytest from hypothesis import given from hypothesis import strategies as st +from websockets.server import WebSocketServerProtocol from _ert.events import ( EESnapshot, @@ -62,6 +64,19 @@ async def mock_failure(message, *args, **kwargs): await evaluator.run_and_get_successful_realizations() +async def test_when_dispatch_is_given_invalid_event_the_socket_is_closed( + make_ee_config, +): + evaluator = EnsembleEvaluator(TestEnsemble(0, 2, 2, id_="0"), make_ee_config()) + + socket = MagicMock(spec=WebSocketServerProtocol) + socket.__aiter__.return_value = ["invalid_json"] + await evaluator.handle_dispatch(socket) + socket.close.assert_called_once_with( + code=1011, reason="failed handling message 'invalid_json'" + ) + + async def test_no_config_raises_valueerror_when_running(): evaluator = EnsembleEvaluator(TestEnsemble(0, 2, 2, id_="0"), None) with pytest.raises(ValueError, match="no config for evaluator"):