| 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 |
export REQUIRE_PLATFORM='loc:remote fs:shared runner:background' |
| 19 |
. "$(dirname "$0")/test_header" |
| 20 |
set_test_number 6 |
| 21 |
#------------------------------------------------------------------------------- |
| 22 |
time_gt () { |
| 23 |
python3 -c " |
| 24 |
import sys |
| 25 |
from metomi.isodatetime.parsers import TimePointParser |
| 26 |
parser = TimePointParser() |
| 27 |
sys.exit(not parser.parse('$1') > parser.parse('$2')) |
| 28 |
" |
| 29 |
} |
| 30 |
BASE_GLOBAL_CONFIG=" |
| 31 |
[scheduler] |
| 32 |
[[main loop]] |
| 33 |
plugins = health check, auto restart |
| 34 |
[[[auto restart]]] |
| 35 |
interval = PT5S |
| 36 |
[[events]] |
| 37 |
abort on inactivity timeout = True |
| 38 |
abort on stall timeout = True |
| 39 |
inactivity timeout = PT2M |
| 40 |
stall timeout = PT2M |
| 41 |
" |
| 42 |
#------------------------------------------------------------------------------- |
| 43 |
# Test the delayed restart feature |
| 44 |
init_workflow "${TEST_NAME_BASE}" <<< ' |
| 45 |
[scheduler] |
| 46 |
UTC mode = True |
| 47 |
[scheduling] |
| 48 |
initial cycle point = 2000 |
| 49 |
[[graph]] |
| 50 |
P1D = foo |
| 51 |
[runtime] |
| 52 |
[[foo]] |
| 53 |
' |
| 54 |
|
| 55 |
MAX_RESTART_DELAY=30 |
| 56 |
create_test_global_config '' " |
| 57 |
${BASE_GLOBAL_CONFIG} |
| 58 |
[scheduler] |
| 59 |
auto restart delay = PT${MAX_RESTART_DELAY}S |
| 60 |
[[run hosts]] |
| 61 |
available = localhost |
| 62 |
" |
| 63 |
|
| 64 |
# Run workflow. |
| 65 |
cylc play "${WORKFLOW_NAME}" --pause |
| 66 |
poll_workflow_running |
| 67 |
|
| 68 |
# Condemn host - trigger stop-restart. |
| 69 |
create_test_global_config '' " |
| 70 |
${BASE_GLOBAL_CONFIG} |
| 71 |
[scheduler] |
| 72 |
auto restart delay = PT20S |
| 73 |
[[run hosts]] |
| 74 |
available = ${CYLC_TEST_HOST} |
| 75 |
condemned = $(hostname) |
| 76 |
" |
| 77 |
|
| 78 |
# Check stop-restart working. |
| 79 |
FILE=$(cylc cat-log "${WORKFLOW_NAME}" -m p |xargs readlink -f) |
| 80 |
log_scan "${TEST_NAME_BASE}-auto-restart" "${FILE}" 60 1 \ |
| 81 |
'The Cylc workflow host will soon become un-available' \ |
| 82 |
'Workflow will restart in' \ |
| 83 |
"Attempting to restart on \"${CYLC_TEST_HOST}\"" \ |
| 84 |
"Workflow now running on \"${CYLC_TEST_HOST}\"" |
| 85 |
|
| 86 |
# Extract scheduled restart time from the log. |
| 87 |
TIMES=$(grep --color=never 'Workflow will restart in' "${FILE}" | \ |
| 88 |
sed 's/.*will restart in \(.*\)s (at \(.*\))/\1|\2/') |
| 89 |
RESTART_DELAY=$(cut -d '|' -f 1 <<< "${TIMES}") |
| 90 |
RESTART_SCHEDULED_TIME=$(cut -d '|' -f 2 <<< "${TIMES}") |
| 91 |
|
| 92 |
# Extract actual restart time from the log. |
| 93 |
RESTART_TIME=$(grep --color=never 'Attempting to restart' "${FILE}" | \ |
| 94 |
sed 's/\(.*\) INFO.*Attempting to restart.*/\1/') |
| 95 |
|
| 96 |
# Check the restart delay is correct. |
| 97 |
TEST_NAME="${TEST_NAME_BASE}-restart-delay" |
| 98 |
if [[ "${RESTART_DELAY}" -lt "${MAX_RESTART_DELAY}" && "${RESTART_DELAY}" -gt 0 ]] |
| 99 |
then |
| 100 |
ok "${TEST_NAME}" |
| 101 |
else |
| 102 |
fail "${TEST_NAME}" |
| 103 |
fi |
| 104 |
|
| 105 |
# Check the actual restart time is after the scheduled restart time. |
| 106 |
TEST_NAME="${TEST_NAME_BASE}-restart-time" |
| 107 |
if time_gt "${RESTART_TIME}" "${RESTART_SCHEDULED_TIME}"; then |
| 108 |
ok "${TEST_NAME}" |
| 109 |
else |
| 110 |
fail "${TEST_NAME}" |
| 111 |
fi |
| 112 |
|
| 113 |
cylc stop "${WORKFLOW_NAME}" --now --now 2>/dev/null |
| 114 |
|
| 115 |
purge |