Skip to content

Commit

Permalink
Add xtrigger CYLC_PYTHONPATH functional test
Browse files Browse the repository at this point in the history
Ensures that xtrggers in your CYLC_PYTHONPATH
are respected above entry_point xtriggers.
  • Loading branch information
ColemanTom committed Dec 6, 2023
1 parent cd55e6d commit be3e277
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/functional/xtriggers/04-respect-cylc-pythonpath.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------------

# Test persistence of xtrigger results across restart. A cycling task depends
# on a non cycle-point dependent custom xtrigger called "faker". In the first
# cycle point the xtrigger succeeds and returns a result, then a task shuts
# the workflow down. Then we replace the custom xtrigger function with one that
# will fail if called again - which should not happen because the original
# result should be remembered (as this xtrigger is not cycle point dependent).
# Also test the correct result is broadcast to the dependent task before and
# after workflow restart.

. "$(dirname "$0")/test_header"
set_test_number 3

install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"

# Install the succeeding xtrigger function.
export CYLC_PYTHONPATH=${WORKFLOW_RUN_DIR}/dir:${CYLC_PYTHONPATH:-}

# Validate the test workflow.
run_ok "${TEST_NAME_BASE}-val" cylc validate --debug "${WORKFLOW_NAME}"

# Run the first cycle, till auto shutdown by task.
TEST_NAME="${TEST_NAME_BASE}-run"
workflow_run_ok "${TEST_NAME}" cylc play --no-detach --debug "${WORKFLOW_NAME}"

# Check the broadcast result of xtrigger.
cylc cat-log "${WORKFLOW_NAME}" >'scheduler.log.out'
grep_ok "echo overridden, args=('the_args',)" 'scheduler.log.out'

purge
21 changes: 21 additions & 0 deletions tests/functional/xtriggers/04-respect-cylc-pythonpath/dir/echo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


def echo(*args, **kwargs):
print(f"echo overridden, args={args}")
return (True, {})
15 changes: 15 additions & 0 deletions tests/functional/xtriggers/04-respect-cylc-pythonpath/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[scheduler]
cycle point format = %Y
[scheduling]
initial cycle point = 2010
final cycle point = 2011
[[xtriggers]]
x1 = echo("the_args")
[[graph]]
R1 = "@x1 => foo => shutdown"
P1Y = "@x1 => foo"
[runtime]
[[foo]]
script = true
[[shutdown]]
script = "cylc shutdown $CYLC_WORKFLOW_ID"

0 comments on commit be3e277

Please sign in to comment.