| 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 |
# Test restart with stop clock time |
| 19 |
|
| 20 |
. "$(dirname "$0")/test_header" |
| 21 |
|
| 22 |
dumpdbtables() { |
| 23 |
sqlite3 "${WORKFLOW_RUN_DIR}/log/db" \ |
| 24 |
"SELECT * FROM workflow_params WHERE key=='stop_clock_time';" \ |
| 25 |
>'stopclocktime.out' |
| 26 |
} |
| 27 |
|
| 28 |
set_test_number 6 |
| 29 |
|
| 30 |
# Event should look like this: |
| 31 |
# Start workflow |
| 32 |
# At 1/t1, set stop clock time to 60 seconds ahead |
| 33 |
# At 1/t2, stop workflow |
| 34 |
# Restart |
| 35 |
# Workflow runs to stop clock time, reset stop clock time |
| 36 |
init_workflow "${TEST_NAME_BASE}" <<'__FLOW_CONFIG__' |
| 37 |
[task parameters] |
| 38 |
i = 1..10 |
| 39 |
[scheduler] |
| 40 |
[[events]] |
| 41 |
abort on stall timeout = True |
| 42 |
stall timeout = PT0S |
| 43 |
abort on inactivity timeout = True |
| 44 |
inactivity timeout = P2M |
| 45 |
[scheduling] |
| 46 |
[[graph]] |
| 47 |
R1 = t<i-1> => t<i> |
| 48 |
[runtime] |
| 49 |
[[t<i>]] |
| 50 |
script = sleep 10 |
| 51 |
[[t<i=1>]] |
| 52 |
script = """ |
| 53 |
CLOCKTIME="$(($(date +%s) + 60))" |
| 54 |
echo "${CLOCKTIME}" >"${CYLC_WORKFLOW_RUN_DIR}/clocktime" |
| 55 |
cylc stop -w "$(date --date="@${CLOCKTIME}" +%FT%T%:z)" "${CYLC_WORKFLOW_ID}" |
| 56 |
""" |
| 57 |
[[t<i=2>]] |
| 58 |
script = cylc stop "${CYLC_WORKFLOW_ID}" |
| 59 |
__FLOW_CONFIG__ |
| 60 |
|
| 61 |
run_ok "${TEST_NAME_BASE}-validate" cylc validate "${WORKFLOW_NAME}" |
| 62 |
|
| 63 |
workflow_run_ok "${TEST_NAME_BASE}-run" cylc play "${WORKFLOW_NAME}" --no-detach |
| 64 |
read -r CLOCKTIME <"${WORKFLOW_RUN_DIR}/clocktime" |
| 65 |
dumpdbtables |
| 66 |
cmp_ok 'stopclocktime.out' <<<"stop_clock_time|${CLOCKTIME}" |
| 67 |
|
| 68 |
workflow_run_ok "${TEST_NAME_BASE}-restart-1" \ |
| 69 |
cylc play "${WORKFLOW_NAME}" --no-detach |
| 70 |
dumpdbtables |
| 71 |
cmp_ok 'stopclocktime.out' <<<"stop_clock_time|" |
| 72 |
cut -d ' ' -f 4- "${WORKFLOW_RUN_DIR}/log/scheduler/log" >'log.edited' |
| 73 |
if [[ "$(date +%:z)" == '+00:00' ]]; then |
| 74 |
CLOCKTIMESTR="$(date --date="@${CLOCKTIME}" +%FT%TZ)" |
| 75 |
else |
| 76 |
CLOCKTIMESTR="$(date --date="@${CLOCKTIME}" +%FT%T%:z)" |
| 77 |
fi |
| 78 |
contains_ok 'log.edited' <<__LOG__ |
| 79 |
+ stop clock time = ${CLOCKTIME} (${CLOCKTIMESTR}) |
| 80 |
Wall clock stop time reached: ${CLOCKTIMESTR} |
| 81 |
__LOG__ |
| 82 |
|
| 83 |
for i in {01..10}; do |
| 84 |
ST_FILE="${WORKFLOW_RUN_DIR}/log/job/1/t_i${i}/01/job.status" |
| 85 |
if [[ -e "${ST_FILE}" ]]; then |
| 86 |
JOB_ID="$(awk -F= '$1 == "CYLC_JOB_ID" {print $2}' "${ST_FILE}")" |
| 87 |
poll_pid_done "${JOB_ID}" |
| 88 |
fi |
| 89 |
done |
| 90 |
|
| 91 |
purge |
| 92 |
exit |