Skip to content

Commit

Permalink
Add tests for ipc and tcp ee config
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Dec 17, 2024
1 parent 745d68b commit 2ab4369
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/ert/ensemble_evaluator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/ert/shared/net_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

0 comments on commit 2ab4369

Please sign in to comment.