Debian Codegraph @

tests/functional/restart/41-auto-restart-local-jobs.t

raw
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 # shellcheck disable=SC2153
21 export CYLC_TEST_HOST2="${CYLC_TEST_HOST}"
22 export CYLC_TEST_HOST1="${HOSTNAME}"
23 if ${CYLC_TEST_DEBUG:-false}; then ERR=2; else ERR=1; fi
24 set_test_number 13
25 #-------------------------------------------------------------------------------
26 BASE_GLOBAL_CONFIG="
27 [scheduler]
28 [[main loop]]
29 plugins = health check, auto restart
30 [[[auto restart]]]
31 interval = PT2S
32 [[events]]
33 abort on inactivity timeout = True
34 abort on stall timeout = True
35 inactivity timeout = PT2M
36 stall timeout = PT2M
37 "
38
39 init_workflow "${TEST_NAME_BASE}" <<< '
40 [scheduling]
41 [[graph]]
42 R1 = foo => bar
43 [runtime]
44 [[foo]]
45 # we will trigger bar manually later
46 script = sleep 15; false
47 [[bar]]
48 script = sleep 60
49 '
50 cd "${WORKFLOW_RUN_DIR}" || exit 1
51
52 create_test_global_config '' "
53 ${BASE_GLOBAL_CONFIG}
54 [scheduler]
55 [[run hosts]]
56 available = ${CYLC_TEST_HOST1}
57 "
58
59 cylc play "${WORKFLOW_NAME}"
60 #-------------------------------------------------------------------------------
61 # auto stop-restart - normal mode:
62 # ensure the workflow WAITS for local jobs to complete before restarting
63 TEST_NAME="${TEST_NAME_BASE}-normal-mode"
64
65 cylc workflow-state "${WORKFLOW_NAME}//1/foo:started" \
66 --triggers --interval=1 --max-polls=20 >& $ERR
67
68 create_test_global_config '' "
69 ${BASE_GLOBAL_CONFIG}
70 [scheduler]
71 [[run hosts]]
72 available = ${CYLC_TEST_HOST1}, ${CYLC_TEST_HOST2}
73 condemned = ${CYLC_TEST_HOST1}
74 "
75
76 UUID="$(get_workflow_uuid)"
77 LOG_FILE="$(cylc cat-log "${WORKFLOW_NAME}" -m p |xargs readlink -f)"
78 log_scan "${TEST_NAME}-stop-log-scan" "${LOG_FILE}" 40 1 \
79 'The Cylc workflow host will soon become un-available' \
80 'Waiting for jobs running on localhost to complete' \
81 'Waiting for jobs running on localhost to complete' \
82 'Workflow shutting down - REQUEST(NOW-NOW)' \
83 "Attempting to restart on \"${CYLC_TEST_HOST2}\""
84 # we shouldn't have any orphaned tasks because we should
85 # have waited for them to complete
86 grep_fail 'orphaned task' "$LOG_FILE"
87
88 run_ok "${TEST_NAME_BASE}-restart" poll_workflow_restart 10 "$UUID"
89 log_scan "${TEST_NAME}-restart-log-scan" "$LOG_FILE" 20 1 \
90 "Workflow now running on \"${CYLC_TEST_HOST2}\""
91 #-------------------------------------------------------------------------------
92 # auto stop-restart - force mode:
93 # ensure the workflow DOESN'T WAIT for local jobs to complete before stopping
94 TEST_NAME="${TEST_NAME_BASE}-force-mode"
95
96 cylc trigger "${WORKFLOW_NAME}//1/bar"
97 cylc workflow-state "${WORKFLOW_NAME}//1/bar:started" \
98 --triggers --interval=1 --max-polls=20 >& $ERR
99
100 create_test_global_config '' "
101 ${BASE_GLOBAL_CONFIG}
102 [scheduler]
103 [[run hosts]]
104 available = ${CYLC_TEST_HOST1}, ${CYLC_TEST_HOST2}
105 condemned = ${CYLC_TEST_HOST2}!
106 "
107
108 LOG_FILE="$(cylc cat-log "${WORKFLOW_NAME}" -m p |xargs readlink -f)"
109 log_scan "${TEST_NAME}-stop-log-scan" "${LOG_FILE}" 40 1 \
110 'The Cylc workflow host will soon become un-available' \
111 'This workflow will be shutdown as the workflow host is unable to continue' \
112 'Workflow shutting down - REQUEST(NOW)' \
113 'Orphaned tasks:' \
114 '* 1/bar (running)'
115
116 cylc stop "${WORKFLOW_NAME}" --now --now 2>/dev/null || true
117 poll_workflow_stopped
118 sleep 1
119 purge
120 exit