| 1 |
#!/usr/bin/env bash |
| 2 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 3 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
#------------------------------------------------------------------------------ |
| 18 |
|
| 19 |
# Test workflow-state xtriggers with workflow depends on an upstream workflow |
| 20 |
# that stops once cycle short, so it should abort with waiting tasks. |
| 21 |
|
| 22 |
. "$(dirname "$0")/test_header" |
| 23 |
set_test_number 8 |
| 24 |
|
| 25 |
install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" |
| 26 |
|
| 27 |
# Register and validate the upstream workflow. |
| 28 |
WORKFLOW_NAME_UPSTREAM="${WORKFLOW_NAME}-upstream" |
| 29 |
cylc install "${TEST_DIR}/${WORKFLOW_NAME}/upstream" --workflow-name="${WORKFLOW_NAME_UPSTREAM}" --no-run-name |
| 30 |
run_ok "${TEST_NAME_BASE}-validate-up" cylc validate --debug "${WORKFLOW_NAME_UPSTREAM}" |
| 31 |
|
| 32 |
# Validate the downstream test workflow. |
| 33 |
run_ok "${TEST_NAME_BASE}-validate" \ |
| 34 |
cylc val --debug --set="UPSTREAM='${WORKFLOW_NAME_UPSTREAM}'" "${WORKFLOW_NAME}" |
| 35 |
|
| 36 |
# Run the upstream workflow and detach (not a test). |
| 37 |
cylc play "${WORKFLOW_NAME_UPSTREAM}" |
| 38 |
|
| 39 |
# Run the test workflow - it should fail after inactivity ... |
| 40 |
TEST_NAME="${TEST_NAME_BASE}-run-fail" |
| 41 |
workflow_run_fail "${TEST_NAME}" \ |
| 42 |
cylc play --set="UPSTREAM='${WORKFLOW_NAME_UPSTREAM}'" --no-detach "${WORKFLOW_NAME}" |
| 43 |
|
| 44 |
WORKFLOW_LOG="$(cylc cat-log -m 'p' "${WORKFLOW_NAME}")" |
| 45 |
grep_ok 'WARNING - inactivity timer timed out after PT20S' "${WORKFLOW_LOG}" |
| 46 |
|
| 47 |
# ... with 2016/foo succeeded and 2016/FAM waiting. |
| 48 |
cylc workflow-state --old-format "${WORKFLOW_NAME}//2016" >'workflow_state.out' |
| 49 |
contains_ok 'workflow_state.out' << __END__ |
| 50 |
foo, 2016, succeeded |
| 51 |
f3, 2016, waiting |
| 52 |
f1, 2016, waiting |
| 53 |
f2, 2016, waiting |
| 54 |
__END__ |
| 55 |
|
| 56 |
# Check broadcast of xtrigger outputs to dependent tasks. |
| 57 |
JOB_LOG="$(cylc cat-log -f 'j' -m 'p' "${WORKFLOW_NAME}//2015/f1")" |
| 58 |
contains_ok "${JOB_LOG}" << __END__ |
| 59 |
upstream_workflow="${WORKFLOW_NAME_UPSTREAM}" |
| 60 |
upstream_task="foo" |
| 61 |
upstream_point="2015" |
| 62 |
upstream_trigger="data_ready" |
| 63 |
__END__ |
| 64 |
|
| 65 |
# Check broadcast of xtrigger outputs is recorded: 1) in the workflow log... |
| 66 |
# |
| 67 |
# Lines are those which should appear after a '<datetimestamp> INFO - Broadcast |
| 68 |
# set' ('+') and later '... INFO - Broadcast cancelled:' ('-') line, where we |
| 69 |
# use as a test case an arbitrary task where such setting & cancellation occurs: |
| 70 |
contains_ok "${WORKFLOW_LOG}" << __LOG_BROADCASTS__ |
| 71 |
${LOG_INDENT}+ [2014/f1] [environment]upstream_workflow=${WORKFLOW_NAME_UPSTREAM} |
| 72 |
${LOG_INDENT}+ [2014/f1] [environment]upstream_task=foo |
| 73 |
${LOG_INDENT}+ [2014/f1] [environment]upstream_point=2014 |
| 74 |
${LOG_INDENT}+ [2014/f1] [environment]upstream_trigger=data_ready |
| 75 |
${LOG_INDENT}- [2014/f1] [environment]upstream_workflow=${WORKFLOW_NAME_UPSTREAM} |
| 76 |
${LOG_INDENT}- [2014/f1] [environment]upstream_task=foo |
| 77 |
${LOG_INDENT}- [2014/f1] [environment]upstream_point=2014 |
| 78 |
${LOG_INDENT}- [2014/f1] [environment]upstream_trigger=data_ready |
| 79 |
__LOG_BROADCASTS__ |
| 80 |
# ... and 2) in the DB. |
| 81 |
TEST_NAME="${TEST_NAME_BASE}-check-broadcast-in-db" |
| 82 |
if ! command -v 'sqlite3' >'/dev/null'; then |
| 83 |
skip 1 "sqlite3 not installed?" |
| 84 |
fi |
| 85 |
DB_FILE="${RUN_DIR}/${WORKFLOW_NAME}/log/db" |
| 86 |
NAME='db-broadcast-states.out' |
| 87 |
sqlite3 "${DB_FILE}" \ |
| 88 |
'SELECT change, point, namespace, key, value FROM broadcast_events |
| 89 |
ORDER BY time, change, point, namespace, key' >"${NAME}" |
| 90 |
contains_ok "${NAME}" << __DB_BROADCASTS__ |
| 91 |
+|2014|f1|[environment]upstream_workflow|${WORKFLOW_NAME_UPSTREAM} |
| 92 |
+|2014|f1|[environment]upstream_task|foo |
| 93 |
+|2014|f1|[environment]upstream_point|2014 |
| 94 |
+|2014|f1|[environment]upstream_trigger|data_ready |
| 95 |
-|2014|f1|[environment]upstream_workflow|${WORKFLOW_NAME_UPSTREAM} |
| 96 |
-|2014|f1|[environment]upstream_task|foo |
| 97 |
-|2014|f1|[environment]upstream_point|2014 |
| 98 |
-|2014|f1|[environment]upstream_trigger|data_ready |
| 99 |
__DB_BROADCASTS__ |
| 100 |
|
| 101 |
purge |
| 102 |
|
| 103 |
# Clean up the upstream workflow, just in case (expect error here, but exit 0): |
| 104 |
cylc stop --now "${WORKFLOW_NAME_UPSTREAM}" --max-polls=20 --interval=2 \ |
| 105 |
>'/dev/null' 2>&1 |
| 106 |
purge "${WORKFLOW_NAME_UPSTREAM}" |