From 220728e6fd9cd82daedc18a06b73d53d2cd95675 Mon Sep 17 00:00:00 2001 From: Eivind Jahren Date: Sun, 14 Jan 2024 12:59:37 +0100 Subject: [PATCH] Extend license retry to more error messages --- .../ert/forward-models/res/script/ecl_run.py | 4 +- tests/unit_tests/shared/share/test_ecl_run.py | 38 +++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py b/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py index 3c12fad46fe..57a3c2f3725 100644 --- a/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py +++ b/src/ert/shared/share/ert/forward-models/res/script/ecl_run.py @@ -363,7 +363,9 @@ def runEclipse(self, eclrun_config=None, retries_left=2, backoff_sleep=None): try: self.assertECLEND() except RuntimeError as err: - if "LICENSE FAILURE" in err.args[0] and retries_left > 0: + if ( + "LICENSE ERROR" in err.args[0] or "LICENSE FAILURE" in err.args[0] + ) and retries_left > 0: time_to_wait = backoff_sleep + int( random() * self.LICENSE_RETRY_STAGGER_FACTOR ) diff --git a/tests/unit_tests/shared/share/test_ecl_run.py b/tests/unit_tests/shared/share/test_ecl_run.py index 860e42191cc..d2917658a40 100644 --- a/tests/unit_tests/shared/share/test_ecl_run.py +++ b/tests/unit_tests/shared/share/test_ecl_run.py @@ -569,7 +569,26 @@ def test_slurm_env_parsing(): @pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Flaky bash mock on mac") -def test_ecl100_retries_once_on_license_failure(tmp_path, monkeypatch): +@pytest.mark.parametrize( + "error_text", + [ + """\ +Errors 1 +Bugs 0 + @-- ERROR AT TIME 0.0 DAYS ( 1-JAN-2000): + @ LICENSE ERROR -1 FOR MULTI-SEGMENT WELL OPTION + @ FEATURE IS INVALID. CHECK YOUR LICENSE FILE AND + @ THE LICENSE LOG FILE + """, + """\ +Errors 1 +Bugs 0 + @-- ERROR AT TIME 0.0 DAYS ( 1-JAN-2000): + @ LICENSE FAILURE: ERROR NUMBER IS -33 + """, + ], +) +def test_ecl100_retries_once_on_license_failure(error_text, tmp_path, monkeypatch): mock_eclipse_path = tmp_path / "mock_eclipse100" with open(tmp_path / "mock_config.yaml", "w", encoding="utf-8") as fp: yaml.dump( @@ -584,18 +603,13 @@ def test_ecl100_retries_once_on_license_failure(tmp_path, monkeypatch): case_path = tmp_path / "CASE.DATA" case_path.write_text("", encoding="utf-8") mock_eclipse_path.write_text( - dedent( - """\ - #!/usr/bin/bash - echo 'Errors 1 - Bugs 0 - @-- ERROR AT TIME 0.0 DAYS ( 1-JAN-2000): - @ LICENSE FAILURE: ERROR NUMBER IS -33' > CASE.PRT - echo 'Called mock' >> mock_log - """ - ), + f"""#!/usr/bin/bash +echo '{error_text}' > CASE.PRT +echo 'Called mock' >> mock_log +""", encoding="utf-8", ) + print(mock_eclipse_path.read_text()) mock_eclipse_path.chmod( stat.S_IEXEC | stat.S_IWUSR | mock_eclipse_path.stat().st_mode ) @@ -606,7 +620,7 @@ def test_ecl100_retries_once_on_license_failure(tmp_path, monkeypatch): erun.LICENSE_FAILURE_SLEEP_FACTOR = 1 erun.LICENSE_RETRY_STAGGER_FACTOR = 1 - with pytest.raises(RuntimeError, match="LICENSE FAILURE"): + with pytest.raises(RuntimeError, match="LICENSE"): erun.runEclipse() max_attempts = 3 assert (tmp_path / "mock_log").read_text() == "Called mock\n" * max_attempts