| 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 job submission with a very chatty command. |
| 19 |
# + Simulate "cylc jobs-submit" getting killed half way through. |
| 20 |
|
| 21 |
export REQUIRE_PLATFORM='runner:at' |
| 22 |
|
| 23 |
. "$(dirname "$0")/test_header" |
| 24 |
set_test_number 15 |
| 25 |
|
| 26 |
# This test relies on jobs inheriting the scheduler environment: the job |
| 27 |
# submission command bin/talkingnonsense reads COPYING from $CYLC_REPO_DIR |
| 28 |
# and writes to $CYLC_WORKFLOW_RUN_DIR. |
| 29 |
|
| 30 |
create_test_global_config " |
| 31 |
[scheduler] |
| 32 |
process pool timeout = PT10S |
| 33 |
[platforms] |
| 34 |
[[$CYLC_TEST_PLATFORM]] |
| 35 |
job runner command template = talkingnonsense %(job)s |
| 36 |
clean job submission environment = False |
| 37 |
" |
| 38 |
|
| 39 |
install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" |
| 40 |
|
| 41 |
run_ok "${TEST_NAME_BASE}-validate" cylc validate "${WORKFLOW_NAME}" |
| 42 |
|
| 43 |
workflow_run_ok "${TEST_NAME_BASE}-workflow-run" \ |
| 44 |
cylc play --debug --no-detach "${WORKFLOW_NAME}" --reference-test |
| 45 |
|
| 46 |
# Logged killed jobs-submit command |
| 47 |
cylc cat-log "${WORKFLOW_NAME}" | sed -n ' |
| 48 |
/\[jobs-submit \(cmd\|ret_code\|out\|err\)\]/,+2{ |
| 49 |
s/^.*\(\[jobs-submit\)/\1/p |
| 50 |
}' >'log' |
| 51 |
contains_ok 'log' <<'__OUT__' |
| 52 |
[jobs-submit ret_code] -9 |
| 53 |
[jobs-submit err] killed on timeout (PT10S) |
| 54 |
__OUT__ |
| 55 |
|
| 56 |
# Logged jobs that called talkingnonsense |
| 57 |
sed -n 's/\(\[jobs-submit out\]\) .*\(|1\/\)/\1 \2/p' 'log' >'log2' |
| 58 |
N=0 |
| 59 |
while read -r; do |
| 60 |
TAIL="${REPLY#"${WORKFLOW_RUN_DIR}"/log/job/}" |
| 61 |
TASK_JOB="${TAIL%/job}" |
| 62 |
contains_ok 'log2' <<<"[jobs-submit out] |${TASK_JOB}|1|None" |
| 63 |
((N += 1)) |
| 64 |
done <"${WORKFLOW_RUN_DIR}/talkingnonsense.out" |
| 65 |
# Logged jobs that did not call talkingnonsense |
| 66 |
for I in $(eval echo "{$N..9}"); do |
| 67 |
contains_ok 'log2' <<<"[jobs-submit out] |1/nh${I}/01|1" |
| 68 |
done |
| 69 |
|
| 70 |
# Task pool in database contains the correct states |
| 71 |
TEST_NAME="${TEST_NAME_BASE}-db-task-pool" |
| 72 |
DB_FILE="${WORKFLOW_RUN_DIR}/log/db" |
| 73 |
QUERY="SELECT cycle, name, status FROM task_states WHERE name LIKE 'nh%'" |
| 74 |
run_ok "$TEST_NAME" sqlite3 "$DB_FILE" "$QUERY" |
| 75 |
sort "${TEST_NAME}.stdout" > "${TEST_NAME}.stdout.sorted" |
| 76 |
cmp_ok "${TEST_NAME}.stdout.sorted" << '__OUT__' |
| 77 |
1|nh0|submit-failed |
| 78 |
1|nh1|submit-failed |
| 79 |
1|nh2|submit-failed |
| 80 |
1|nh3|submit-failed |
| 81 |
1|nh4|submit-failed |
| 82 |
1|nh5|submit-failed |
| 83 |
1|nh6|submit-failed |
| 84 |
1|nh7|submit-failed |
| 85 |
1|nh8|submit-failed |
| 86 |
1|nh9|submit-failed |
| 87 |
__OUT__ |
| 88 |
|
| 89 |
purge |
| 90 |
exit |