Skip to content

Commit

Permalink
Add scheduler unit test for propagation of dispatch information to jo…
Browse files Browse the repository at this point in the history
…bs file (#6807)

Add scheduler unit test for propagation of dispatch info to jobs file
  • Loading branch information
jonathan-eq authored Dec 20, 2023
1 parent 1221607 commit 87da99a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/ert/scheduler/local_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
72 changes: 67 additions & 5 deletions tests/unit_tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import shutil
from pathlib import Path
from typing import Sequence

import pytest

Expand All @@ -12,28 +11,55 @@
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,
run_arg=run_arg,
num_cpu=1,
job_script=str(shutil.which("job_dispatch.py")),
)
return realization


async def test_empty():
Expand Down Expand Up @@ -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",
[
Expand Down

0 comments on commit 87da99a

Please sign in to comment.