Skip to content

Commit

Permalink
Fix unbound event
Browse files Browse the repository at this point in the history
Validation is raised from dispatch_event_from_json so
event is unbound.
  • Loading branch information
eivindjahren committed Oct 31, 2024
1 parent c4e1365 commit ea220bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ert/ensemble_evaluator/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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

Expand Down
15 changes: 15 additions & 0 deletions tests/ert/unit_tests/ensemble_evaluator/test_ensemble_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -63,6 +65,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"):
Expand Down

0 comments on commit ea220bb

Please sign in to comment.