Skip to content

Explicit server port allocation in tests #2095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,15 @@ def remove_none_available_config(configs, config_names):
)


current_port = ansys.dpf.core.server_types.DPF_DEFAULT_PORT


def get_next_port() -> int:
global current_port
current_port += 1
return current_port


@pytest.fixture(
scope="package",
params=configsserver_type,
Expand All @@ -446,7 +455,7 @@ def remove_none_available_config(configs, config_names):
def server_type(request):
if core.global_server().config == request.param and os.name != "posix":
return core.global_server()
server = core.start_local_server(config=request.param, as_global=False)
server = core.start_local_server(config=request.param, as_global=False, port=get_next_port())
return server


Expand All @@ -470,7 +479,7 @@ def server_type(request):
def server_type_remote_process(request):
if core.global_server().config == request.param and os.name != "posix":
return core.global_server()
server = core.start_local_server(config=request.param, as_global=False)
server = core.start_local_server(config=request.param, as_global=False, port=get_next_port())
return server


Expand Down Expand Up @@ -509,7 +518,7 @@ def config_server_type(request):
def server_type_legacy_grpc(request):
if core.global_server().config == request.param and os.name != "posix":
return core.global_server()
return core.start_local_server(config=request.param, as_global=False)
return core.start_local_server(config=request.param, as_global=False, port=get_next_port())


@pytest.fixture(
Expand All @@ -522,7 +531,7 @@ def server_type_legacy_grpc(request):
def server_clayer_remote_process(request):
if core.global_server().config == request.param and os.name != "posix":
return core.global_server()
server = core.start_local_server(config=request.param, as_global=False)
server = core.start_local_server(config=request.param, as_global=False, port=get_next_port())
return server


Expand All @@ -543,7 +552,7 @@ def server_clayer_remote_process(request):
def server_clayer(request):
if core.global_server().config == request.param and os.name != "posix":
return core.global_server()
server = core.start_local_server(config=request.param, as_global=False)
server = core.start_local_server(config=request.param, as_global=False, port=get_next_port())
return server


Expand Down Expand Up @@ -584,15 +593,17 @@ def __getitem__(self, item):
conf = ServerConfig(protocol=CommunicationProtocols.gRPC, legacy=False)
if len(self._local_servers) <= item:
while len(self._local_servers) <= item:
self._local_servers.append(core.start_local_server(as_global=False, config=conf))
self._local_servers.append(
core.start_local_server(as_global=False, config=conf, port=get_next_port())
)
try:
self._local_servers[item].info
return self._local_servers[item]
except:
for iter in range(0, self._max_iter):
try:
self._local_servers[item] = core.start_local_server(
as_global=False, config=conf
as_global=False, config=conf, port=get_next_port()
)
self._local_servers[item].info
break
Expand Down
Loading