Skip to content

Commit

Permalink
zmq: add test for zmq start up failure when port already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Jan 28, 2025
1 parent 2c8503c commit 281d673
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/ert/ensemble_evaluator/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,8 @@ def log_exception(task_exception: BaseException, task_name: str) -> None:
)

async def run_and_get_successful_realizations(self) -> list[int]:
await self._start_running()

try:
await self._start_running()
await self._monitor_and_handle_tasks()
finally:
self._server_done.set()
Expand Down
14 changes: 14 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 @@ -5,6 +5,7 @@
from unittest.mock import patch

import pytest
import zmq.asyncio
from hypothesis import given
from hypothesis import strategies as st
from pydantic import ValidationError
Expand Down Expand Up @@ -97,6 +98,19 @@ async def test_evaluator_handles_dispatchers_connected(
assert evaluator._dispatchers_empty.is_set()


async def test_evaluator_raises_on_fail_start(make_ee_config):
ee_config = make_ee_config(use_ipc_protocol=False)
ctx = zmq.asyncio.Context()
socket = ctx.socket(zmq.ROUTER)
try:
socket.bind(f"tcp://*:{ee_config.router_port}")
evaluator = EnsembleEvaluator(TestEnsemble(0, 2, 2, id_="0"), ee_config)
with pytest.raises(RuntimeError, match="Address already in use"):
await evaluator.run_and_get_successful_realizations()
finally:
ctx.destroy()


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 281d673

Please sign in to comment.