Skip to content

Commit

Permalink
fix: avoid MAPDL commands execution when gRPC connection fails. (#3686)
Browse files Browse the repository at this point in the history
* fix: avoid MAPDL commands execution when gRPC connection fails.

* chore: adding changelog file 3686.fixed.md [dependabot-skip]

* fix: test

* fix: test

* ci: avoid saving when exiting

* fix: adding missing arguments

* test: marking `test_extract` test as flaky. See #2435

* test: improving tests

* fix: making sure we generate the RST file

* test: fix

* fix: test

* fix: (again) test

---------

Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
  • Loading branch information
germa89 and pyansys-ci-bot authored Jan 23, 2025
1 parent ed13b59 commit 3a5732c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3686.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: avoid MAPDL commands execution when gRPC connection fails.
5 changes: 5 additions & 0 deletions src/ansys/mapdl/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ def wrapper(*args, **kwargs):
f"$ export PYMAPDL_MAX_MESSAGE_LENGTH={lim_}"
)

# Every try to reconnecto to MAPDL failed
# So let's avoid execution from now on.
# The above exception should not break the channel.
mapdl._exited = True

if error.code() == grpc.StatusCode.UNAVAILABLE:
# Very likely the MAPDL server has died.
suggestion = (
Expand Down
9 changes: 8 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def is_exited(mapdl: Mapdl):
mapdl = Mapdl(port=port, ip=ip)

except MapdlConnectionError as err:
from conftest import DEBUG_TESTING, ON_LOCAL

# Registering error.
LOG.info(str(err))

Expand All @@ -285,7 +287,12 @@ def is_exited(mapdl: Mapdl):
override=True,
run_location=mapdl._path,
cleanup_on_exit=mapdl._cleanup,
log_apdl=log_apdl(),
license_server_check=False,
start_timeout=50,
loglevel="DEBUG" if DEBUG_TESTING else "ERROR",
# If the following file names are changed, update `ci.yml`.
log_apdl="pymapdl.apdl" if DEBUG_TESTING else None,
mapdl_output="apdl.out" if (DEBUG_TESTING and ON_LOCAL) else None,
)

LOG.info("Successfully re-connected to MAPDL")
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,9 @@ def mapdl(request, tmpdir_factory):
mapdl._local = True
mapdl._exited = False
assert mapdl.finish_job_on_exit
mapdl.exit(save=True, force=True)

mapdl.exit(save=False, force=True)

assert mapdl._exited
assert "MAPDL exited" in str(mapdl)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ def _raise_error_code(*args, **kwargs):
# passing mapdl to simulate the function `_raise_error_code` to be a method.
mapdl.prep7(mapdl)

assert mapdl.is_alive
assert not mapdl.is_alive
mapdl._exited = False


def test_generic_grpc_exception_exited(monkeypatch, grpc_channel):
Expand Down
15 changes: 13 additions & 2 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,9 +1542,20 @@ def test_file_command_remote(mapdl, cube_solve, tmpdir):

mapdl.post1()
# this file should exist remotely
rst_file_name = "file.rst"
assert rst_file_name in mapdl.list_files()
rst_file_name = mapdl.result_file
if not rst_file_name in mapdl.list_files():
mapdl.solution()
mapdl.solve()

mapdl.finish()
mapdl.save()

rst_file_name = os.path.basename(rst_file_name)
assert (
rst_file_name in mapdl.list_files()
), f"File {os.path.basename(rst_file_name)} is not in {mapdl.list_files()}"

mapdl.post1()
mapdl.file(rst_file_name) # checking we can read it.

with pytest.raises(FileNotFoundError):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_3d_array(mapdl, cleared):
def test_parameter_with_spaces(mapdl, cleared):
string_ = "DEV:F10X, front weights "
mapdl.run(f"*SET,SIMULATION,'{string_}'")
mapdl.parsav()
mapdl.parsav("all", fname="file", ext="parm")
mapdl.clear()
mapdl.parres("NEW", fname="file", ext="parm")
assert mapdl.starstatus()
Expand Down
1 change: 1 addition & 0 deletions tests/test_xpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def test_goto(xpl):

@requires("ansys-math-core")
@pytest.mark.usefixtures("check_supports_extract")
@pytest.mark.xfail(reason="Flaky test. See #2435")
def test_extract(self, xpl):
# expecting fixture to already have a non-result file open
assert xpl._filename[-3:] != "rst"
Expand Down

0 comments on commit 3a5732c

Please sign in to comment.