Skip to content

Commit

Permalink
Fix bug where Everest would not start with relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Nov 14, 2024
1 parent 120659c commit 79aad48
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/everest/detached/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def start_server(config: EverestConfig, debug: bool = False) -> Driver:

driver = create_driver(get_server_queue_options(config))
try:
args = ["--config-file", config.config_file]
args = ["--config-file", str(config.config_path)]
if debug:
args.append("--debug")
await driver.submit(0, "everserver", *args)
Expand Down
46 changes: 46 additions & 0 deletions tests/everest/test_detached.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import stat
from pathlib import Path
from unittest.mock import patch

import pytest
Expand All @@ -10,6 +12,7 @@
LsfQueueOptions,
SlurmQueueOptions,
)
from ert.scheduler.event import FinishedEvent
from everest.config import EverestConfig
from everest.config.server_config import ServerConfig
from everest.config.simulator_config import SimulatorConfig
Expand Down Expand Up @@ -294,3 +297,46 @@ def test_generate_queue_options_no_config():
def test_generate_queue_options_use_simulator_values(queue_options, expected_result):
config = EverestConfig.with_defaults(**{"simulator": queue_options})
assert get_server_queue_options(config) == expected_result


@pytest.mark.timeout(5) # Simulation might not finish
@pytest.mark.integration_test
@pytest.mark.xdist_group(name="starts_everest")
async def test_starting_not_in_folder(tmp_path, monkeypatch):
"""
This tests that the second argument to the everserver is the config
file, and that the config file exists. This is a regression test for
a bug that happened when everest was started from a different dir
than the config file was in.
"""

async def server_running():
while True:
event = await driver.event_queue.get()
if isinstance(event, FinishedEvent) and event.iens == 0:
return event

os.makedirs(tmp_path / "new_folder")
monkeypatch.chdir(tmp_path / "new_folder")
everest_config = EverestConfig.with_defaults()
everest_config.dump("minimal_config.yml")
everest_config.config_path = Path("minimal_config.yml").absolute()
monkeypatch.chdir(tmp_path)
monkeypatch.setenv("PATH", f".:{os.environ['PATH']}")
everserver_path = Path("everserver")
with open(everserver_path, "w", encoding="utf-8") as file: # noqa: ASYNC230
file.write(
"""#!/usr/bin/env python
import sys
from pathlib import Path
if __name__ == "__main__":
config_path = sys.argv[2]
if not Path(config_path).exists():
raise ValueError(f"config_path ({config_path}) does not exist")
"""
)
everserver_path.chmod(everserver_path.stat().st_mode | stat.S_IEXEC)
makedirs_if_needed(everest_config.output_dir, roll_if_exists=True)
driver = await start_server(everest_config, debug=True)
final_state = await server_running()
assert final_state.returncode == 0

0 comments on commit 79aad48

Please sign in to comment.