From 2ab43691bdf6732696f8e1c4593a3a4fc14d9ee0 Mon Sep 17 00:00:00 2001 From: Julius Parulek Date: Tue, 17 Dec 2024 23:12:35 +0100 Subject: [PATCH] Add tests for ipc and tcp ee config --- src/ert/ensemble_evaluator/config.py | 7 ++-- src/ert/shared/net_utils.py | 1 - .../test_ensemble_evaluator_config.py | 32 +++++++++---------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/ert/ensemble_evaluator/config.py b/src/ert/ensemble_evaluator/config.py index d58fc02d018..913524d70ab 100644 --- a/src/ert/ensemble_evaluator/config.py +++ b/src/ert/ensemble_evaluator/config.py @@ -34,6 +34,7 @@ def __init__( self.router_port: int | None = None self.url = f"ipc:///tmp/socket-{uuid.uuid4().hex[:8]}" self.token: str | None = None + self._socket_handle: socket | None = None self.server_public_key: bytes | None = None self.server_secret_key: bytes | None = None @@ -50,8 +51,10 @@ def __init__( self.server_public_key, self.server_secret_key = zmq.curve_keypair() self.token = self.server_public_key.decode("utf-8") - def get_socket(self) -> socket.socket: - return self._socket_handle.dup() + def get_socket(self) -> socket.socket | None: + if self._socket_handle: + return self._socket_handle.dup() + return None def get_connection_info(self) -> EvaluatorConnectionInfo: return EvaluatorConnectionInfo( diff --git a/src/ert/shared/net_utils.py b/src/ert/shared/net_utils.py index 2c377c2aca5..fbcb80cebf7 100644 --- a/src/ert/shared/net_utils.py +++ b/src/ert/shared/net_utils.py @@ -110,7 +110,6 @@ def _bind_socket( if will_close_then_reopen_socket: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - # sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) else: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 0) diff --git a/tests/ert/unit_tests/ensemble_evaluator/test_ensemble_evaluator_config.py b/tests/ert/unit_tests/ensemble_evaluator/test_ensemble_evaluator_config.py index 2741aa4da9e..2d8f2189fe7 100644 --- a/tests/ert/unit_tests/ensemble_evaluator/test_ensemble_evaluator_config.py +++ b/tests/ert/unit_tests/ensemble_evaluator/test_ensemble_evaluator_config.py @@ -3,7 +3,7 @@ from ert.ensemble_evaluator.config import EvaluatorServerConfig -def test_load_config(unused_tcp_port): +def test_ensemble_evaluator_config_tcp_protocol(unused_tcp_port): fixed_port = range(unused_tcp_port, unused_tcp_port) serv_config = EvaluatorServerConfig( custom_port_range=fixed_port, @@ -19,19 +19,19 @@ def test_load_config(unused_tcp_port): assert url.port == expected_port assert serv_config.url == expected_url assert serv_config.token is not None - # TODO REFACTOR - # sock = serv_config.get_socket() - # assert sock is not None - # assert not sock._closed - # sock.close() + assert serv_config.server_public_key is not None + assert serv_config.server_secret_key is not None + sock = serv_config.get_socket() + assert sock is not None + assert not sock._closed + sock.close() - # ee_config = EvaluatorServerConfig( - # custom_port_range=range(1024, 65535), - # custom_host="127.0.0.1", - # use_token=False, - # generate_cert=False, - # ) - # sock = ee_config.get_socket() - # assert sock is not None - # assert not sock._closed - # sock.close() + +def test_ensemble_evaluator_config_ipc_protocol(): + serv_config = EvaluatorServerConfig(use_ipc_protocol=True, use_token=False) + + assert serv_config.url.startswith("ipc:///tmp/socket-") + assert serv_config.token is None + assert serv_config.server_public_key is None + assert serv_config.server_secret_key is None + assert serv_config.get_socket() is None