Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try make pre/post experiment hook test not flaky #9677

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/test_ert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ jobs:
- name: CLI Test
if: inputs.test-type == 'cli-tests'
run: |
pytest --cov=ert --cov=everest --cov=_ert --cov-report=xml:cov1.xml --junit-xml=junit.xml -o junit_family=legacy -v --benchmark-disable --dist loadgroup tests/ert/ui_tests/cli --durations=25
echo {{github.workspace}}
pytest -x --cov=ert --cov=everest --cov=_ert --cov-report=xml:cov1.xml --junit-xml=junit.xml -o junit_family=legacy -v --benchmark-disable --dist loadgroup tests/ert/ui_tests/cli --durations=25

- name: Upload checkme folder if exists
if: ${{ !cancelled() }}
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: folder-artifact
path: '/tmp/pytest-of-runner/**/checkme'

- name: Unit Test
if: inputs.test-type == 'unit-tests'
Expand Down
3 changes: 3 additions & 0 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import logging
import time
import traceback
from collections.abc import Callable, Iterable, Sequence
from fnmatch import fnmatch
from typing import (
Expand Down Expand Up @@ -876,6 +877,8 @@ def iterative_smoother_update(
initial_mask=initial_mask,
)
except Exception as e:
print("Exception!")
traceback.print_tb(e.__traceback__)
progress_callback(
AnalysisErrorEvent(
error_msg=str(e),
Expand Down
5 changes: 5 additions & 0 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import shutil
import time
import traceback
import uuid
from abc import ABC, abstractmethod
from collections import defaultdict
Expand Down Expand Up @@ -233,6 +234,10 @@ def group(cls) -> str | None:
return None

def send_event(self, event: StatusEvents) -> None:
if hasattr(event, "error_msg"):
traceback.print_stack()
print(event.error_msg)

self._status_queue.put(event)

def send_smoother_event(
Expand Down
25 changes: 13 additions & 12 deletions tests/ert/ui_tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,11 @@ def test_that_stop_on_fail_workflow_jobs_stop_ert(


@pytest.mark.usefixtures("copy_poly_case")
def test_that_pre_post_experiment_hook_works(monkeypatch, capsys):
monkeypatch.setattr(_ert.threading, "_can_raise", False)

@pytest.mark.parametrize(
"mode",
[ITERATIVE_ENSEMBLE_SMOOTHER_MODE, ES_MDA_MODE, ENSEMBLE_SMOOTHER_MODE],
)
def test_that_pre_post_experiment_hook_works(capsys, mode):
# The executable
with open("hello_post_exp.sh", "w", encoding="utf-8") as f:
f.write(
Expand All @@ -542,7 +544,7 @@ def test_that_pre_post_experiment_hook_works(monkeypatch, capsys):

# The workflow
with open("SAY_HELLO_POST_EXP.wf", "w", encoding="utf-8") as s:
s.write("""dump_final_ensemble_id""")
s.write("""alias_for_hello_post_exp_wfjob""")

# The executable
with open("hello_pre_exp.sh", "w", encoding="utf-8") as f:
Expand All @@ -562,31 +564,30 @@ def test_that_pre_post_experiment_hook_works(monkeypatch, capsys):

# The workflow
with open("SAY_HELLO_PRE_EXP.wf", "w", encoding="utf-8") as s:
s.write("""dump_first_ensemble_id""")
s.write("""alias_for_hello_pre_exp_wfjob""")

with open("poly.ert", mode="a", encoding="utf-8") as fh:
fh.write(
dedent(
"""
NUM_REALIZATIONS 2

LOAD_WORKFLOW_JOB SAY_HELLO_POST_EXP dump_final_ensemble_id
LOAD_WORKFLOW_JOB SAY_HELLO_POST_EXP alias_for_hello_post_exp_wfjob
LOAD_WORKFLOW SAY_HELLO_POST_EXP.wf POST_EXPERIMENT_DUMP
HOOK_WORKFLOW POST_EXPERIMENT_DUMP POST_EXPERIMENT

LOAD_WORKFLOW_JOB SAY_HELLO_PRE_EXP dump_first_ensemble_id
LOAD_WORKFLOW_JOB SAY_HELLO_PRE_EXP alias_for_hello_pre_exp_wfjob
LOAD_WORKFLOW SAY_HELLO_PRE_EXP.wf PRE_EXPERIMENT_DUMP
HOOK_WORKFLOW PRE_EXPERIMENT_DUMP PRE_EXPERIMENT
"""
)
)

for mode in [ITERATIVE_ENSEMBLE_SMOOTHER_MODE, ES_MDA_MODE, ENSEMBLE_SMOOTHER_MODE]:
run_cli(mode, "--disable-monitor", "poly.ert")
run_cli(mode, "--disable-monitoring", "poly.ert")

captured = capsys.readouterr()
assert "first" in captured.out
assert "just sending regards" in captured.out
captured = capsys.readouterr()
assert "first" in captured.out
assert "just sending regards" in captured.out


@pytest.fixture(name="mock_cli_run")
Expand Down
Loading