Skip to content

Commit

Permalink
fix functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Apr 25, 2024
1 parent c87270b commit 1fcb22c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
29 changes: 21 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from functools import partial
from subprocess import run
from shlex import split
from pathlib import Path
import pytest
from time import sleep
from types import SimpleNamespace
Expand Down Expand Up @@ -218,29 +219,41 @@ def cylc_validate_cli(capsys, caplog):
def mod_cylc_validate_cli(mod_capsys, mod_caplog):
return _cylc_validate_cli(mod_capsys, mod_caplog)


@pytest.fixture
def file_poll():
"""Poll for the existance of a file.
"""
def _inner(fpath: "Path", timeout: int = 5):
def _inner(
fpath: "Path", timeout: int = 5, inverse: bool = False
):
if inverse:
check = lambda f: not f.exists()
else:
check = lambda f: f.exists()

timeout_func(
fpath.exists,
partial(check, fpath),
f'file {fpath} not found after {timeout} seconds'
)
return _inner


@pytest.fixture
def purge_workflow(run_ok):
def purge_workflow(run_ok, file_poll):
"""Ensure workflow is stopped and cleaned"""
def _inner(id_, timeout=5):
run_ok(f'cylc stop {id_} --now --now')
stop = f'cylc stop {id_} --now --now'
clean = f'cylc clean {id_}'
timeout_func(
partial(run_ok, clean),
message=f'Not run after {timeout} seconds: {clean}'
partial(run_ok, stop),
message=f'Not run after {timeout} seconds: {stop}')
file_poll(
Path.home() / 'cylc-run' / id_ / '.service/contact',
inverse=True,
)
timeout_func(
partial(run_ok, clean),
message=f'Not run after {timeout} seconds: {clean}')
return _inner


Expand All @@ -251,7 +264,7 @@ def run_ok():
"""
def _inner(script: str):
result = run(split(script), capture_output=True)
assert result.returncode == 0
assert result.returncode == 0, f'{script} failed: {result.stderr}'
return result
return _inner

Expand Down
16 changes: 8 additions & 8 deletions tests/functional/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,12 @@ def test_reinstall_overrides(
See https://github.com/cylc/cylc-flow/issues/5968
"""
(tmp_path / 'flow.cylc').write_text(dedent("""
#!jinja2
[scheduling]\n
[[graph]]\n
R1 = foo\n
[runtime]\n
[[foo]]\n
(tmp_path / 'flow.cylc').write_text(dedent(""" #!jinja2
[scheduling]
[[graph]]
R1 = foo
[runtime]
[[foo]]
script = cylc message -- {{var}}
"""))
(tmp_path / 'rose-suite.conf').write_text(
Expand All @@ -328,12 +327,13 @@ def test_reinstall_overrides(

# Reload the workflow:
run_ok(f'cylc reload {install_results.id}')
# Play workflow
run_ok(f'cylc play --pause {install_results.id}')

# The config being run has been modified:
run_dir = Path.home() / 'cylc-run' / install_results.id
config_log = (run_dir / 'log/config/02-reload-01.cylc')
file_poll(config_log)

assert 'cylc message -- CLIreinstall' in config_log.read_text()

purge_workflow(install_results.id)

0 comments on commit 1fcb22c

Please sign in to comment.