Skip to content

Commit

Permalink
Close Evaluator server for new connections earlier
Browse files Browse the repository at this point in the history
Ensemble evaluator accepted new connections while shutting down before
this commit
  • Loading branch information
JHolba committed Oct 15, 2024
1 parent 10a02f6 commit 353edda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ert/ensemble_evaluator/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ async def _server(self) -> None:
ping_timeout=60,
ping_interval=60,
close_timeout=60,
):
) as server:
self._server_started.set()
await self._server_done.wait()
server.close(close_connections=False)
if self._dispatchers_connected is not None:
logger.debug(
f"Got done signal. {self._dispatchers_connected.qsize()} "
Expand Down
22 changes: 22 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 @@ -94,6 +94,28 @@ async def mock_done_prematurely(message, *args, **kwargs):
await evaluator.run_and_get_successful_realizations()


async def test_new_connections_are_denied_when_evaluator_is_closing_down(
evaluator_to_use,
):
evaluator = evaluator_to_use

class TestMonitor(Monitor):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._connection_timeout = 1

async def new_connection():
await evaluator._server_done.wait()
async with TestMonitor(evaluator._config.get_connection_info()):
pass

new_connection_task = asyncio.create_task(new_connection())
evaluator.stop()

with pytest.raises(RuntimeError):
await new_connection_task


@pytest.fixture(name="evaluator_to_use")
async def evaluator_to_use_fixture(make_ee_config):
ensemble = TestEnsemble(0, 2, 2, id_="0")
Expand Down

0 comments on commit 353edda

Please sign in to comment.