Skip to content

Commit

Permalink
Fix everest logging test
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Dec 5, 2024
1 parent d458a1a commit bcacf2a
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions tests/everest/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import pytest

Expand All @@ -13,14 +14,12 @@
CONFIG_FILE = "config_fm_failure.yml"


def string_exists_in_file(file_path, string):
with open(file_path, "r", encoding="utf-8") as f:
txt = f.read()
return string in txt
def _string_exists_in_file(file_path, string):
return string in Path(file_path).read_text(encoding="utf-8")


@pytest.mark.flaky(reruns=5)
@pytest.mark.timeout(60) # Simulation might not finish
@pytest.mark.timeout(70) # Simulation might not finish
@pytest.mark.integration_test
@pytest.mark.xdist_group(name="starts_everest")
async def test_logging_setup(copy_math_func_test_data_to_tmp):
Expand All @@ -35,8 +34,8 @@ async def server_running():
makedirs_if_needed(everest_config.output_dir, roll_if_exists=True)
driver = await start_server(everest_config, debug=True)
try:
wait_for_server(everest_config.output_dir, 120)
except SystemExit as e:
wait_for_server(everest_config.output_dir, 60)
except (SystemExit, RuntimeError) as e:
raise e
await server_running()

Expand All @@ -56,17 +55,16 @@ async def server_running():
assert os.path.exists(everest_log_path)
assert os.path.exists(endpoint_log_path)

assert string_exists_in_file(everest_log_path, "everest DEBUG:")
assert string_exists_in_file(
forward_model_log_path,
"forward_models ERROR: Batch: 0 Realization: 0 Simulation: 2 "
"Job: toggle_failure Failed Error: 0",
assert _string_exists_in_file(everest_log_path, "everest DEBUG:")
assert _string_exists_in_file(
forward_model_log_path, "Exception: Failing simulation_2 by request!"
)
assert string_exists_in_file(
assert _string_exists_in_file(
forward_model_log_path, "Exception: Failing simulation_2" " by request!"
)

assert string_exists_in_file(
endpoint_log_path,
"everserver INFO: / entered from",
)
endpoint_logs = Path(endpoint_log_path).read_text(encoding="utf-8")
# Avoid cases where optimization finished before we get a chance to check that
# the everest server has started
if endpoint_logs:
assert "everserver INFO: / entered from" in endpoint_logs

0 comments on commit bcacf2a

Please sign in to comment.