diff --git a/src/ert/scheduler/local_driver.py b/src/ert/scheduler/local_driver.py index c4b9ae3bc40..24ee3ba5ce4 100644 --- a/src/ert/scheduler/local_driver.py +++ b/src/ert/scheduler/local_driver.py @@ -3,9 +3,7 @@ import asyncio import os from asyncio.subprocess import Process -from typing import ( - MutableMapping, -) +from typing import MutableMapping from ert.scheduler.driver import Driver, JobEvent diff --git a/tests/unit_tests/scheduler/test_scheduler.py b/tests/unit_tests/scheduler/test_scheduler.py index ea9da7b3b7f..e50fa4536cf 100644 --- a/tests/unit_tests/scheduler/test_scheduler.py +++ b/tests/unit_tests/scheduler/test_scheduler.py @@ -2,7 +2,6 @@ import json import shutil from pathlib import Path -from typing import Sequence import pytest @@ -12,21 +11,47 @@ from ert.scheduler import scheduler +def create_jobs_json(realization: Realization) -> None: + jobs = { + "global_environment": {}, + "config_path": "/dev/null", + "config_file": "/dev/null", + "jobList": [ + { + "name": forward_model.name, + "executable": forward_model.executable, + "argList": forward_model.arglist, + } + for forward_model in realization.forward_models + ], + "run_id": "0", + "ert_pid": "0", + "real_id": str(realization.iens), + } + realization_run_path = Path(realization.run_arg.runpath) + realization_run_path.mkdir() + with open(realization_run_path / "jobs.json", mode="w", encoding="utf-8") as f: + json.dump(jobs, f) + + @pytest.fixture def realization(storage, tmp_path): ensemble = storage.create_experiment().create_ensemble(name="foo", ensemble_size=1) + return create_stub_realization(ensemble, tmp_path, 0) + +def create_stub_realization(ensemble, base_path: Path, iens) -> Realization: run_arg = RunArg( run_id="", ensemble_storage=ensemble, - iens=0, + iens=iens, itr=0, - runpath=str(tmp_path), + runpath=str(base_path / f"realization-{iens}"), job_name="", ) - return Realization( - iens=0, + realization = Realization( + iens=iens, forward_models=[], active=True, max_runtime=None, @@ -34,6 +59,7 @@ def realization(storage, tmp_path): num_cpu=1, job_script=str(shutil.which("job_dispatch.py")), ) + return realization async def test_empty(): @@ -88,6 +114,42 @@ async def kill(): assert killed +async def test_add_dispatch_information_to_jobs_file(storage, tmp_path: Path): + test_ee_uri = "ws://test_ee_uri.com/121/" + test_ens_id = "test_ens_id121" + test_ee_token = "test_ee_token_t0k€n121" + test_ee_cert = "test_ee_cert121.pem" + + ensemble_size = 10 + + ensemble = storage.create_experiment().create_ensemble( + name="foo", ensemble_size=ensemble_size + ) + realizations = [ + create_stub_realization(ensemble, tmp_path, iens) + for iens in range(ensemble_size) + ] + + sch = scheduler.Scheduler() + sch.set_ee_info(test_ee_uri, test_ens_id, test_ee_cert, test_ee_token) + + for realization in realizations: + sch.add_realization(realization) + create_jobs_json(realization) + + sch.add_dispatch_information_to_jobs_file() + + for realization in realizations: + job_file_path = Path(realization.run_arg.runpath, "jobs.json") + content: dict = json.loads(job_file_path.read_text(encoding="utf-8")) + assert content["ens_id"] == test_ens_id + assert content["real_id"] == str(realization.iens) + assert content["dispatch_url"] == test_ee_uri + assert content["ee_token"] == test_ee_token + assert content["ee_cert_path"] == test_ee_cert + assert type(content["jobList"]) == list and len(content["jobList"]) == 0 + + @pytest.mark.parametrize( "max_submit", [