Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Dec 14, 2023
1 parent 60c08c2 commit cb84c5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/ert/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def ainit(self) -> None:
self._events = asyncio.Queue()

def add_realization(
self, real: Realization, callback_timeout: Callable[[int], None]
self, real: Realization, callback_timeout: Callable[[int], None] = None
) -> None:

Check failure on line 68 in src/ert/scheduler/scheduler.py

View workflow job for this annotation

GitHub Actions / type-checking (3.11)

Incompatible default for argument "callback_timeout" (default has type "None", argument has type "Callable[[int], None]")
self._jobs[real.iens] = Job(self, real)

Expand Down
28 changes: 13 additions & 15 deletions tests/unit_tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import asyncio
import json
import shutil
from dataclasses import asdict
from pathlib import Path
from typing import Sequence

import pytest

Expand All @@ -29,19 +27,19 @@ def create_jobs_json(realization: Realization) -> None:
"config_file": "/dev/null",
"jobList": [
{
"name": step.name,
"executable": step.executable,
"argList": step.arglist,
"name": forward_model.name,
"executable": forward_model.executable,
"argList": forward_model.arglist,
}
for step in realization.forward_models
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", "w") as f:
with open(realization_run_path / "jobs.json", mode="w", encoding="utf-8") as f:
json.dump(jobs, f)


Expand All @@ -51,13 +49,13 @@ def realization(storage, tmp_path):
return create_stub_realization(ensemble, tmp_path, 0)


def create_stub_realization(ensemble, base_path: Path, iens):
def create_stub_realization(ensemble, base_path: Path, iens) -> Realization:
run_arg = RunArg(
run_id="",
ensemble_storage=ensemble,
iens=iens,
itr=0,
runpath=str(base_path / str(iens)),
runpath=str(base_path / f"realization-{iens}"),
job_name="",
)

Expand All @@ -83,14 +81,14 @@ async def test_single_job(tmp_path: Path, realization):
realization.forward_models = [step]

sch = scheduler.Scheduler()
sch.add_realization(realization, callback_timeout=lambda _: None)
sch.add_realization(realization)

create_jobs_json(realization)
sch.add_dispatch_information_to_jobs_file()

assert await sch.execute() == EVTYPE_ENSEMBLE_STOPPED
assert (
tmp_path / str(realization.iens) / "testfile"
tmp_path / f"realization-{realization.iens}" / "testfile"
).read_text() == "Hello, world!\n"


Expand All @@ -99,7 +97,7 @@ async def test_cancel(tmp_path: Path, realization):
realization.forward_models = [step]

sch = scheduler.Scheduler()
sch.add_realization(realization, callback_timeout=lambda _: None)
sch.add_realization(realization)

create_jobs_json(realization)
sch.add_dispatch_information_to_jobs_file()
Expand All @@ -113,8 +111,8 @@ async def test_cancel(tmp_path: Path, realization):
sch.kill_all_jobs()
await scheduler_task

assert (tmp_path / str(realization.iens) / "a").exists()
assert not (tmp_path / str(realization.iens) / "b").exists()
assert (tmp_path / f"realization-{realization.iens}" / "a").exists()
assert not (tmp_path / f"realization-{realization.iens}" / "b").exists()


def test_add_dispatch_information_to_jobs_file(storage, tmp_path: Path):
Expand All @@ -137,7 +135,7 @@ def test_add_dispatch_information_to_jobs_file(storage, tmp_path: Path):
sch.set_ee_info(test_ee_uri, test_ens_id, test_ee_cert, test_ee_token)

for realization in realizations:
sch.add_realization(realization, callback_timeout=lambda _: None)
sch.add_realization(realization)
create_jobs_json(realization)

sch.add_dispatch_information_to_jobs_file()
Expand Down

0 comments on commit cb84c5c

Please sign in to comment.