Skip to content

Commit

Permalink
Add ForwardModelRunnerExceptionclass
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Nov 19, 2024
1 parent a0f33a0 commit 784237d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/_ert/forward_model_runner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
logger = logging.getLogger(__name__)


class ForwardModelRunnerException(Exception):
pass


def _setup_reporters(
is_interactive_run,
ens_id,
Expand Down Expand Up @@ -172,11 +176,11 @@ async def _main(
f"job_dispatch failed due to {oserror}. Stopping and cleaning up."
)
await let_reporters_finish(reporters)
raise SystemExit(1)
raise ForwardModelRunnerException from oserror

if isinstance(job_status, Finish) and not job_status.success():
await let_reporters_finish(reporters)
raise SystemExit(1)
raise ForwardModelRunnerException
except asyncio.CancelledError:
await let_reporters_finish(reporters)
raise SystemExit(1)
raise ForwardModelRunnerException from None
17 changes: 11 additions & 6 deletions tests/ert/unit_tests/forward_model_runner/test_job_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
from textwrap import dedent
from unittest.mock import mock_open, patch

from _ert.forward_model_runner.reporting.message import Finish, Init
import pandas as pd
import psutil
import pytest

import _ert.forward_model_runner.cli
from _ert.forward_model_runner.cli import JOBS_FILE, _setup_reporters, main
from _ert.forward_model_runner.cli import (
JOBS_FILE,
ForwardModelRunnerException,
_setup_reporters,
main,
)
from _ert.forward_model_runner.forward_model_step import killed_by_oom
from _ert.forward_model_runner.reporting import Event, Interactive
from _ert.forward_model_runner.reporting.message import Finish, Init
from tests.ert.utils import _mock_ws_task, async_wait_until, wait_until


Expand Down Expand Up @@ -351,6 +356,7 @@ async def test_job_dispatch_kills_itself_after_unsuccessful_job(unused_tcp_port)
patch("_ert.forward_model_runner.cli.open", new=mock_open(read_data=jobs_json)),
patch("_ert.forward_model_runner.cli.ForwardModelRunner") as mock_runner,
):

async def mock_run_method(*args, **kwargs):
events = [
Init([], 0, 0),
Expand All @@ -359,13 +365,12 @@ async def mock_run_method(*args, **kwargs):
for event in events:
await asyncio.sleep(0)
yield event

mock_runner.return_value.run = mock_run_method

async with _mock_ws_task(host, port, []):
tsk = asyncio.create_task(main(["script.py"]))
await tsk
assert isinstance(tsk.exception, SystemExit)
await asyncio.sleep(0)
with pytest.raises(ForwardModelRunnerException):
await main(["script.py"])


@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="No oom_score on MacOS")
Expand Down

0 comments on commit 784237d

Please sign in to comment.