Skip to content

Commit

Permalink
Add cylc-set func tests TEMP
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoliver committed Dec 1, 2023
1 parent aaafdc6 commit 6b392c5
Show file tree
Hide file tree
Showing 21 changed files with 585 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/functional/cylc-set/00-set-succeeded.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/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/>.
#-------------------------------------------------------------------------------

# "cylc set" proposal examples.
# Set incomplete failed tasks to succeeded.

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

install_and_validate
reftest_run

for TASK in foo bar
do
sqlite3 ~/cylc-run/"${WORKFLOW_NAME}"/log/db \
"SELECT status FROM task_states WHERE name is \"$TASK\"" > "${TASK}.1"

cmp_ok ${TASK}.1 - << __OUT__
succeeded
__OUT__

sqlite3 ~/cylc-run/"${WORKFLOW_NAME}"/log/db \
"SELECT outputs FROM task_outputs WHERE name is \"$TASK\"" > "${TASK}.2"

# Json string list of outputs from the db may not be ordered correctly.
# E.g., '["submitted", "started", "succeeded", "failed"]'.
python3 - << __END__ > "${TASK}.3"
import json
with open("${TASK}.2", 'r') as f:
print(
','.join(
sorted(
json.load(f)
)
)
)
__END__

cmp_ok "${TASK}.3" - << __OUT__
failed,started,submitted,succeeded
__OUT__

done
purge
41 changes: 41 additions & 0 deletions tests/functional/cylc-set/00-set-succeeded/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 1. foo and bar fail incomplete.
# 2. setter sets foo and bar to succeeded.
# 3. foo and bar are completed, post<m> runs, scheduler shuts down.

[scheduler]
[[events]]
inactivity timeout = PT30S
abort on inactivity timeout = True
expected task failures = 1/foo, 1/bar

[task parameters]
m = 1..2

[scheduling]
[[graph]]
R1 = """
foo & bar => post<m>
setter
"""
[runtime]
[[post<m>]]
[[foo, bar]]
script = false
[[setter]]
script = """
# wait for foo and bar to fail.
for TASK in foo bar
do
cylc workflow-state \
--max-polls=10 \
--interval=1 \
--task=$TASK \
--point=${CYLC_TASK_CYCLE_POINT} \
--status=failed \
$CYLC_WORKFLOW_ID
done
# set foo succeeded (via --output)
cylc set -o succeeded $CYLC_WORKFLOW_ID//$CYLC_TASK_CYCLE_POINT/foo
# set bar succeeded (via default)
cylc set $CYLC_WORKFLOW_ID//$CYLC_TASK_CYCLE_POINT/bar
"""
5 changes: 5 additions & 0 deletions tests/functional/cylc-set/00-set-succeeded/reference.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1/setter -triggered off [] in flow 1
1/foo -triggered off [] in flow 1
1/bar -triggered off [] in flow 1
1/post_m1 -triggered off ['1/bar', '1/foo'] in flow 1
1/post_m2 -triggered off ['1/bar', '1/foo'] in flow 1
37 changes: 37 additions & 0 deletions tests/functional/cylc-set/01-off-flow-pre.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/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/>.
#-------------------------------------------------------------------------------

# "cylc set" proposal examples.
# Set off-flow prerequisites to prevent a new flow from stalling.

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

install_and_validate
reftest_run

grep_workflow_log_ok ab "1/a does not depend on 1/b_cold:succeeded"
grep_workflow_log_ok ac "1/a does not depend on 1/c_cold:succeeded"

grep_workflow_log_ok ba "1/b does not depend on 1/a_cold:succeeded"
grep_workflow_log_ok bc "1/b does not depend on 1/c_cold:succeeded"

grep_workflow_log_ok ca "1/c does not depend on 1/a_cold:succeeded"
grep_workflow_log_ok cb "1/c does not depend on 1/b_cold:succeeded"

purge
35 changes: 35 additions & 0 deletions tests/functional/cylc-set/01-off-flow-pre/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# start a new flow after setting off-flow prerequites to avoid stall.

[scheduler]
[[events]]
stall timeout = PT0S
abort on stall timeout = True
inactivity timeout = PT30S
abort on inactivity timeout = True

[scheduling]
[[graph]]
R1 = """
# the tasks we want the flow to run
a => b => c => reflow
# the off-flow prerequisites
a_cold => a
b_cold => b
c_cold => c
"""
[runtime]
[[a, b, c]]
[[a_cold, b_cold, c_cold]]
[[reflow]]
script = """
if (( CYLC_TASK_SUBMIT_NUMBER == 1 )); then
# set off-flow prerequisites (and trigger 1/a)
cylc set --flow=new \
--pre=1/a_cold:succeeded \
--pre=1/b_cold:succeeded \
--pre=1/c_cold:succeeded \
${CYLC_WORKFLOW_ID}//1/a \
${CYLC_WORKFLOW_ID}//1/b \
${CYLC_WORKFLOW_ID}//1/c
fi
"""
11 changes: 11 additions & 0 deletions tests/functional/cylc-set/01-off-flow-pre/reference.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1/c_cold -triggered off [] in flow 1
1/a_cold -triggered off [] in flow 1
1/b_cold -triggered off [] in flow 1
1/a -triggered off ['1/a_cold'] in flow 1
1/b -triggered off ['1/a', '1/b_cold'] in flow 1
1/c -triggered off ['1/b', '1/c_cold'] in flow 1
1/reflow -triggered off ['1/c'] in flow 1
1/a -triggered off ['1/a_cold'] in flow 2
1/b -triggered off ['1/a', '1/b_cold'] in flow 2
1/c -triggered off ['1/b', '1/c_cold'] in flow 2
1/reflow -triggered off ['1/c'] in flow 2
44 changes: 44 additions & 0 deletions tests/functional/cylc-set/02-off-flow-out.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/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/>.
#-------------------------------------------------------------------------------

# "cylc set" proposal examples.
# Set off-flow outputs to prevent a new flow from stalling.

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

install_and_validate
reftest_run

# Check that we set:
# - all the required outputs of a_cold
# - the requested and implied outputs of b_cold and c_cold

grep_workflow_log_ok grep-a1 'implied output "submitted" of 1/a_cold'
grep_workflow_log_ok grep-a2 'implied output "started" of 1/a_cold'
grep_workflow_log_ok grep-a3 'completing output "succeeded" of 1/a_cold'

grep_workflow_log_ok grep-b1 'implied output "submitted" of 1/b_cold'
grep_workflow_log_ok grep-b2 'implied output "started" of 1/b_cold'
grep_workflow_log_ok grep-b3 'completing output "succeeded" of 1/b_cold'

grep_workflow_log_ok grep-c1 'implied output "submitted" of 1/c_cold'
grep_workflow_log_ok grep-c2 'implied output "started" of 1/c_cold'
grep_workflow_log_ok grep-c3 'completing output "succeeded" of 1/c_cold'

purge
32 changes: 32 additions & 0 deletions tests/functional/cylc-set/02-off-flow-out/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# start a new flow after setting off-flow outputs to avoid stall.

[scheduler]
[[events]]
stall timeout = PT0S
abort on stall timeout = True
inactivity timeout = PT30S
abort on inactivity timeout = True

[scheduling]
[[graph]]
R1 = """
# the tasks we want the flow to run
a => b => c => reflow
# the off-flow prerequisites
a_cold => a
b_cold => b
c_cold => c
"""
[runtime]
[[a, b, c]]
[[a_cold, b_cold, c_cold]]
[[reflow]]
script = """
if (( CYLC_TASK_SUBMIT_NUMBER == 1 )); then
# set off-flow outputs of x_cold
cylc set --flow=new \
${CYLC_WORKFLOW_ID}//1/a_cold \
${CYLC_WORKFLOW_ID}//1/b_cold \
${CYLC_WORKFLOW_ID}//1/c_cold
fi
"""
11 changes: 11 additions & 0 deletions tests/functional/cylc-set/02-off-flow-out/reference.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1/c_cold -triggered off [] in flow 1
1/a_cold -triggered off [] in flow 1
1/b_cold -triggered off [] in flow 1
1/a -triggered off ['1/a_cold'] in flow 1
1/b -triggered off ['1/a', '1/b_cold'] in flow 1
1/c -triggered off ['1/b', '1/c_cold'] in flow 1
1/reflow -triggered off ['1/c'] in flow 1
1/a -triggered off ['1/a_cold'] in flow 2
1/b -triggered off ['1/a', '1/b_cold'] in flow 2
1/c -triggered off ['1/b', '1/c_cold'] in flow 2
1/reflow -triggered off ['1/c'] in flow 2
69 changes: 69 additions & 0 deletions tests/functional/cylc-set/03-set-failed.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/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/>.
#-------------------------------------------------------------------------------

# "cylc set" proposal examples.
# check that we can set a dead orphaned job to failed.

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

install_and_validate

run_ok play-it cylc play --debug "${WORKFLOW_NAME}"

poll_grep_workflow_log -E "1/foo.* \(internal\)submitted"

cylc set -o failed "${WORKFLOW_NAME}//1/foo"

poll_grep_workflow_log -E "1/foo.* \(internal\)failed"
poll_grep_workflow_log -E "1/foo.* did not complete required outputs"

cylc stop --now --now --interval=2 --max-polls=5 "${WORKFLOW_NAME}"

# Check the log for:
# - set completion message
# - implied outputs reported as already completed

# order of output completion is currently not fixed (using a set of outputs).
grep_workflow_log_ok grep-1 'set: implied output "submitted" of 1/foo' # already completed'
grep_workflow_log_ok grep-2 'set: implied output "started" of 1/foo' # already completed'
grep_workflow_log_ok grep-3 'set: completing output "failed" of 1/foo'

# Check the DB records all the outputs.

sqlite3 ~/cylc-run/"${WORKFLOW_NAME}"/log/db \
"SELECT outputs FROM task_outputs WHERE name is \"foo\"" > db-foo.1

# Json string list of outputs from the db may not be ordered correctly.
python3 - << __END__ > db-foo.2
import json
with open("db-foo.1", 'r') as f:
print(
','.join(
sorted(
json.load(f)
)
)
)
__END__

cmp_ok "db-foo.2" - << __OUT__
failed,started,submitted
__OUT__

purge
18 changes: 18 additions & 0 deletions tests/functional/cylc-set/03-set-failed/flow.cylc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# A single task that dies silently, requiring set to failed

[scheduler]
[[events]]
inactivity timeout = PT20S
abort on inactivity timeout = True

[scheduling]
[[graph]]
R1 = "foo"

[runtime]
[[foo]]
init-script = cylc__job__disable_fail_signals
script = """
cylc__job__wait_cylc_message_started
exit 1
"""
Loading

0 comments on commit 6b392c5

Please sign in to comment.