Skip to content

Commit 3a5732c

Browse files
fix: avoid MAPDL commands execution when gRPC connection fails. (#3686)
* 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 <[email protected]>
1 parent ed13b59 commit 3a5732c

File tree

8 files changed

+34
-6
lines changed

8 files changed

+34
-6
lines changed

doc/changelog.d/3686.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: avoid MAPDL commands execution when gRPC connection fails.

src/ansys/mapdl/core/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ def wrapper(*args, **kwargs):
361361
f"$ export PYMAPDL_MAX_MESSAGE_LENGTH={lim_}"
362362
)
363363

364+
# Every try to reconnecto to MAPDL failed
365+
# So let's avoid execution from now on.
366+
# The above exception should not break the channel.
367+
mapdl._exited = True
368+
364369
if error.code() == grpc.StatusCode.UNAVAILABLE:
365370
# Very likely the MAPDL server has died.
366371
suggestion = (

tests/common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ def is_exited(mapdl: Mapdl):
269269
mapdl = Mapdl(port=port, ip=ip)
270270

271271
except MapdlConnectionError as err:
272+
from conftest import DEBUG_TESTING, ON_LOCAL
273+
272274
# Registering error.
273275
LOG.info(str(err))
274276

@@ -285,7 +287,12 @@ def is_exited(mapdl: Mapdl):
285287
override=True,
286288
run_location=mapdl._path,
287289
cleanup_on_exit=mapdl._cleanup,
288-
log_apdl=log_apdl(),
290+
license_server_check=False,
291+
start_timeout=50,
292+
loglevel="DEBUG" if DEBUG_TESTING else "ERROR",
293+
# If the following file names are changed, update `ci.yml`.
294+
log_apdl="pymapdl.apdl" if DEBUG_TESTING else None,
295+
mapdl_output="apdl.out" if (DEBUG_TESTING and ON_LOCAL) else None,
289296
)
290297

291298
LOG.info("Successfully re-connected to MAPDL")

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,9 @@ def mapdl(request, tmpdir_factory):
620620
mapdl._local = True
621621
mapdl._exited = False
622622
assert mapdl.finish_job_on_exit
623-
mapdl.exit(save=True, force=True)
623+
624+
mapdl.exit(save=False, force=True)
625+
624626
assert mapdl._exited
625627
assert "MAPDL exited" in str(mapdl)
626628

tests/test_grpc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,8 @@ def _raise_error_code(*args, **kwargs):
654654
# passing mapdl to simulate the function `_raise_error_code` to be a method.
655655
mapdl.prep7(mapdl)
656656

657-
assert mapdl.is_alive
657+
assert not mapdl.is_alive
658+
mapdl._exited = False
658659

659660

660661
def test_generic_grpc_exception_exited(monkeypatch, grpc_channel):

tests/test_mapdl.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,9 +1542,20 @@ def test_file_command_remote(mapdl, cube_solve, tmpdir):
15421542

15431543
mapdl.post1()
15441544
# this file should exist remotely
1545-
rst_file_name = "file.rst"
1546-
assert rst_file_name in mapdl.list_files()
1545+
rst_file_name = mapdl.result_file
1546+
if not rst_file_name in mapdl.list_files():
1547+
mapdl.solution()
1548+
mapdl.solve()
15471549

1550+
mapdl.finish()
1551+
mapdl.save()
1552+
1553+
rst_file_name = os.path.basename(rst_file_name)
1554+
assert (
1555+
rst_file_name in mapdl.list_files()
1556+
), f"File {os.path.basename(rst_file_name)} is not in {mapdl.list_files()}"
1557+
1558+
mapdl.post1()
15481559
mapdl.file(rst_file_name) # checking we can read it.
15491560

15501561
with pytest.raises(FileNotFoundError):

tests/test_parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_3d_array(mapdl, cleared):
410410
def test_parameter_with_spaces(mapdl, cleared):
411411
string_ = "DEV:F10X, front weights "
412412
mapdl.run(f"*SET,SIMULATION,'{string_}'")
413-
mapdl.parsav()
413+
mapdl.parsav("all", fname="file", ext="parm")
414414
mapdl.clear()
415415
mapdl.parres("NEW", fname="file", ext="parm")
416416
assert mapdl.starstatus()

tests/test_xpl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def test_goto(xpl):
184184

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

0 commit comments

Comments
 (0)