Skip to content

Add run-before / run-after hooks for system tests#849

Open
PranjalManhgaye wants to merge 2 commits into
precice:developfrom
PranjalManhgaye:feature/827-run-before
Open

Add run-before / run-after hooks for system tests#849
PranjalManhgaye wants to merge 2 commits into
precice:developfrom
PranjalManhgaye:feature/827-run-before

Conversation

@PranjalManhgaye

Copy link
Copy Markdown
Collaborator

Summary

  • add optional run-before / run-after in tests.yaml
  • run in copied tutorial dir : before build (run-before, before max_time), after simulation (run-after, before fieldcompare)
  • Wire water-hammer and partitioned-pipe-multiscale with ./set-case.sh 1d3d
  • document in readme
    fixes Run a command before starting a test #827

Test plan

  • i have checked tests.yaml still parses with the new fields
  • i also ran a quick smoke test : run-before switches the symlink and max_time runs after it
  • i have ran water-hammer locally with docker , build and run passed, and i saw the run-before log in the output
  • tests without hooks should behave the same as before (quickstart / others not touched)

Fixes precice#827. Per-test shell commands run in the copied tutorial directory
before Docker build (run-before) or after simulation (run-after). Wire
water-hammer and partitioned-pipe-multiscale with ./set-case.sh 1d3d.

@MakisH MakisH left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for implementing! Here are some comments before testing on GHA.

Comment thread changelog-entries/849.md
@@ -0,0 +1 @@
- Add optional `run-before` and `run-after` hooks in `tests.yaml` for system test setup ([#827](https://github.com/precice/tutorials/pull/849)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Add optional `run-before` and `run-after` hooks in `tests.yaml` for system test setup ([#827](https://github.com/precice/tutorials/pull/849)).
- Added optional `run-before` and `run-after` hooks in `tests.yaml` for system test setup ([#849](https://github.com/precice/tutorials/pull/849)).

Comment on lines +222 to +223
run_before: Optional[str] = None
run_after: Optional[str] = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the Optional, you need the | syntax. Also in the _run_hook.

Comment on lines +789 to +791
"""
Run a shell command in the copied tutorial directory (e.g. run-before / run-after).
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall concept needs to be explained in the PR description.

Comment on lines +807 to +810
if result.stdout:
logging.debug(f"{stage} stdout for {self}:\n{result.stdout.rstrip()}")
if result.stderr:
logging.debug(f"{stage} stderr for {self}:\n{result.stderr.rstrip()}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why distinguishing between stdout and stderr here? What is the motivation behind this?

Comment on lines +8 to +14
def _validate_hook_command(field_name: str, value, tutorial: Tutorial) -> Optional[str]:
if value is None:
return None
if not isinstance(value, str) or not value.strip():
raise ValueError(
f"{field_name} must be a non-empty string for tutorial '{tutorial}', got {value!r}")
return value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a dedicated function needed to check if field_name is non-empty?

Why is it called field_name?

Also, if it is empty, it should just do nothing, right? That would make the code simpler.

Comment thread tools/tests/README.md

Use the `max_time` or `max_time_windows` parameters to restrict the runtime of the test to the first few coupling time windows, to save time. Aim for a runtime of less than a minute (assuming cached components), if possible.

Some tutorials require setup before the simulation (e.g. switching configuration files). Use optional `run-before` and `run-after` fields in `tests.yaml` to run shell commands in the copied tutorial directory after copying and before Docker build (`run-before`), or after the simulation and before field comparison (`run-after`). Example:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why before the Docker build? I would expect that to be after building and before running. Is there a particular use case or complication I overlook?

For the set-case, it should make no difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run a command before starting a test

2 participants