Debian Codegraph @

tests/functional/restart/57-ghost-job.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 # Test restarting when there is a "ghost job" in the DB (has a submit_time in
19 # task_jobs table but no submit_exit_time or run_time)
20
21 . "$(dirname "$0")/test_header"
22 set_test_number 9
23
24 install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"
25 mkdir "${WORKFLOW_RUN_DIR}/.service"
26 DB_PATH="${WORKFLOW_RUN_DIR}/.service/db"
27 sqlite3 "$DB_PATH" < db.sqlite3
28
29 query_db_task_jobs() {
30 TEST_NAME="$1"
31 sqlite3 "$DB_PATH" \
32 'SELECT cycle, name, submit_num FROM task_jobs' > "${TEST_NAME}.stdout"
33 }
34
35 get_submit_time() {
36 sqlite3 "$DB_PATH" 'SELECT time_submit FROM task_jobs'
37 }
38
39 # cylc client input stored as var:
40 read -r -d '' gqlQuery << _args_
41 {
42 "request_string": "
43 query {
44 workflows(ids: [\"${WORKFLOW_NAME}\"]) {
45 jobs {
46 cyclePoint, name, submitNum
47 }
48 }
49 }"
50 }
51 _args_
52
53 # -----------------------------------------------------------------------------
54
55 run_ok "${TEST_NAME_BASE}-validate" cylc validate "${WORKFLOW_NAME}"
56
57 workflow_run_ok "${TEST_NAME_BASE}-restart" cylc play --upgrade -vv "${WORKFLOW_NAME}" --pause
58
59 # There will be 1 ghost job in DB:
60 TEST_NAME="${TEST_NAME_BASE}-db-query-1"
61 query_db_task_jobs "$TEST_NAME"
62 cmp_ok "${TEST_NAME}.stdout" << EOF
63 1|foo|1
64 EOF
65
66 # Get submit time for that job:
67 orig_submit_time="$(get_submit_time)"
68
69 # Ghost job should not be in data store:
70 TEST_NAME="${TEST_NAME_BASE}-datastore-query-1"
71
72 run_graphql_ok "$TEST_NAME" "$WORKFLOW_NAME" "$gqlQuery"
73
74 cmp_json "${TEST_NAME}-cmp" "${TEST_NAME}.stdout" << EOF
75 {
76 "workflows": [{
77 "jobs": []
78 }]
79 }
80 EOF
81
82 workflow_run_ok "${TEST_NAME_BASE}-resume" cylc play --upgrade "${WORKFLOW_NAME}"
83 poll_workflow_stopped
84
85 # Job should have been replaced in DB with same submit num:
86 TEST_NAME="${TEST_NAME_BASE}-db-query-2"
87 query_db_task_jobs "$TEST_NAME"
88
89 cmp_ok "${TEST_NAME}.stdout" << EOF
90 1|foo|1
91 EOF
92
93 # Submit time should be different however:
94 TEST_NAME="${TEST_NAME_BASE}-submit-time-cmp"
95 if [[ "$(get_submit_time)" != "$orig_submit_time" ]]; then
96 ok "$TEST_NAME"
97 else
98 fail "$TEST_NAME" \
99 "Expected time_submit in task_jobs table to be different from original"
100 fi
101
102 # Job should be in data store:
103 TEST_NAME="${TEST_NAME_BASE}-datastore-query-2"
104 cmp_json "${TEST_NAME}-cmp" "${WORKFLOW_RUN_DIR}/work/1/foo/gqlResponse.json" << EOF
105 {
106 "workflows": [{
107 "jobs": [{
108 "cyclePoint": "1",
109 "name": "foo",
110 "submitNum": 1
111 }]
112 }]
113 }
114 EOF
115
116 purge