Skip to content
Open
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
1 change: 1 addition & 0 deletions changelog-entries/848.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add optional per-component `build_timeout` in `components.yaml` for the system test Docker build step ([#848](https://github.com/precice/tutorials/pull/848)).

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.

Remember, changelogs are written in past tense:

Suggested change
- Add optional per-component `build_timeout` in `components.yaml` for the system test Docker build step ([#848](https://github.com/precice/tutorials/pull/848)).
- Added optional per-component `build_timeout` in `components.yaml` for the system test Docker build step ([#848](https://github.com/precice/tutorials/pull/848)).

6 changes: 4 additions & 2 deletions tools/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,10 @@ This template defines:

### Timeouts

A `GLOBAL_TIMEOUT` is used for all operations. Its default value is 600s (5min), it is set in the beginning of [`Systemtests.py`](https://github.com/precice/tutorials/blob/develop/tools/tests/systemtests/Systemtest.py), and it can be overridden via the `PRECICE_SYSTEMTESTS_TIMEOUT` environment variable.
Build and run/compare use separate timeouts.

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
Build and run/compare use separate timeouts.
The build and and the run/compare steps use separate timeouts.


Tests can define a different `timeout` in their `tests.yaml` entry, which applies to the running and results comparison steps.
**Build:** Each component in `components.yaml` may define `build_timeout` (seconds). For a test, the build step uses the maximum `build_timeout` among its components; components without `build_timeout` use `DEFAULT_BUILD_TIMEOUT` (600s by default, same as `GLOBAL_TIMEOUT`). Override the default via `PRECICE_SYSTEMTESTS_BUILD_TIMEOUT`.

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.

Does that mean that if I have a test that uses OpenFOAM and DuMux, building the OpenFOAM Docker image will timeout at the DuMux build timeout? Why is that?


**Run and compare:** `GLOBAL_TIMEOUT` defaults to 600s and can be overridden via `PRECICE_SYSTEMTESTS_TIMEOUT`. Tests can define a different `timeout` in their `tests.yaml` entry, which applies to the running and results comparison steps only.

</details>
1 change: 1 addition & 0 deletions tools/tests/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dealii-adapter:

dumux-adapter:
template: component-templates/dumux-adapter.yaml
build_timeout: 1800

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.

DuMux already builds with 600s. Let's set this to 600s, and reduce the GLOBAL_TIMEOUT to 300s. The SU2 adapter probably also needs the 600s.

There will be more cases with longer timeouts later.

build_arguments:
PLATFORM:
default: "ubuntu_2404"
Expand Down
15 changes: 11 additions & 4 deletions tools/tests/metadata_parser/metdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Component:
name: str
template: str
parameters: BuildArguments
build_timeout: Optional[int] = 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.

I think that Optional is not the current way of implementing optional arguments in Python. One reference: https://stackoverflow.com/a/63442322/2254346


def __eq__(self, other):
if isinstance(other, Component):
Expand Down Expand Up @@ -130,11 +131,17 @@ def from_yaml(cls, path):
with open(path, 'r') as f:
data = yaml.safe_load(f)
for component_name in data:
parameters = BuildArguments.from_components_yaml(
data[component_name])
template = data[component_name]["template"]
component_data = data[component_name]
parameters = BuildArguments.from_components_yaml(component_data)
template = component_data["template"]
build_timeout = component_data.get("build_timeout", None)
if build_timeout is not None:
if not isinstance(build_timeout, int) or build_timeout <= 0:
raise ValueError(
f"build_timeout must be a positive integer for component "
f"'{component_name}', got {build_timeout!r}")
components.append(
Component(component_name, template, parameters))
Component(component_name, template, parameters, build_timeout))

return cls(components)

Expand Down
24 changes: 23 additions & 1 deletion tools/tests/systemtests/Systemtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@


GLOBAL_TIMEOUT = int(os.environ.get("PRECICE_SYSTEMTESTS_TIMEOUT", 600))
DEFAULT_BUILD_TIMEOUT = int(

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.

Similar comment as in #847: I get the impression we need a dictionary of defaults here. But maybe in a separate PR.

os.environ.get("PRECICE_SYSTEMTESTS_BUILD_TIMEOUT", GLOBAL_TIMEOUT))
SHORT_TIMEOUT = 10

DIFF_RESULTS_DIR = "diff-results"
Expand Down Expand Up @@ -236,6 +238,24 @@ def __hash__(self) -> int:
def __post_init__(self):
self.__init_args_to_use()
self.env = {}
self.build_timeout = self._resolve_build_timeout()

def _resolve_build_timeout(self) -> int:
"""
Use the maximum build_timeout of the distinct components in this test.
Components without build_timeout use DEFAULT_BUILD_TIMEOUT.
"""
timeouts = []
seen_components = set()
for case in self.case_combination.cases:
if case.component.name in seen_components:
continue
seen_components.add(case.component.name)
if case.component.build_timeout is not None:
timeouts.append(case.component.build_timeout)
else:
timeouts.append(DEFAULT_BUILD_TIMEOUT)
return max(timeouts) if timeouts else DEFAULT_BUILD_TIMEOUT

def __init_args_to_use(self):
"""
Expand Down Expand Up @@ -714,6 +734,8 @@ def _build_docker(self):
Builds the docker image
"""
logging.debug(f"Building docker image for {self}")
logging.info(
f"Using build timeout {self.build_timeout}s for {self}")
time_start = time.perf_counter()
docker_compose_content = self.__get_docker_compose_file()
with open(self.system_test_dir / "docker-compose.tutorial.yaml", 'w') as file:
Expand All @@ -729,7 +751,7 @@ def _build_docker(self):
'build',
],
"build",
GLOBAL_TIMEOUT,
self.build_timeout,
)
elapsed_time = time.perf_counter() - time_start
return DockerComposeResult(exit_code, stdout_data, stderr_data, self, elapsed_time)
Expand Down