Debian Codegraph @

tests/flakyfunctional/database/00-simple.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 # Workflow database content, a basic non-cycling workflow of 3 tasks
19 . "$(dirname "$0")/test_header"
20 if ! command -v 'sqlite3' >'/dev/null'; then
21 skip_all "sqlite3 not installed?"
22 fi
23 set_test_number 21
24
25 install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"
26
27 run_ok "${TEST_NAME_BASE}-validate" cylc validate "${WORKFLOW_NAME}"
28 workflow_run_ok "${TEST_NAME_BASE}-run" cylc play --debug --no-detach "${WORKFLOW_NAME}"
29
30 DB_FILE="${RUN_DIR}/${WORKFLOW_NAME}/log/db"
31
32 NAME='schema.out'
33 ORIG="${TEST_SOURCE_DIR}/${TEST_NAME_BASE}/${NAME}"
34 SORTED_ORIG="sorted-${NAME}"
35 sqlite3 "${DB_FILE}" ".schema" | env LANG='C' sort >"${NAME}"
36 env LANG='C' sort "${ORIG}" > "${SORTED_ORIG}"
37 cmp_ok "${NAME}" "${SORTED_ORIG}"
38
39 NAME='select-workflow-params.out'
40 sqlite3 "${DB_FILE}" \
41 "SELECT key, value FROM workflow_params
42 WHERE key != 'uuid_str' AND key != 'cycle_point_tz' ORDER BY key" \
43 >"${NAME}"
44 cmp_ok "${NAME}" << __EOF__
45 UTC_mode|0
46 cycle_point_format|
47 cylc_version|$(cylc --version)
48 fcp|
49 icp|1
50 is_paused|0
51 n_restart|0
52 run_mode|live
53 startcp|
54 stop_clock_time|
55 stop_task|
56 stopcp|
57 __EOF__
58
59 NAME='select-task-events.out'
60 sqlite3 "${DB_FILE}" 'SELECT name, cycle, event, message FROM task_events' \
61 >"${NAME}"
62 cmp_ok "${NAME}" << __EOF__
63 foo|1|submitted|
64 foo|1|started|
65 foo|1|succeeded|
66 bar|1|submitted|
67 bar|1|started|
68 bar|1|succeeded|
69 baz|1|submitted|
70 baz|1|started|
71 baz|1|succeeded|
72 __EOF__
73
74 NAME='select-task-jobs.out'
75 sqlite3 "${DB_FILE}" \
76 'SELECT cycle, name, submit_num, try_num, submit_status, run_status,
77 platform_name, job_runner_name
78 FROM task_jobs ORDER BY name' \
79 >"${NAME}"
80 LOCALHOST="$(localhost_fqdn)"
81 # FIXME: recent Travis CI failure
82 sed -i "s/localhost/${LOCALHOST}/" "${NAME}"
83 cmp_ok "${NAME}" - <<__SELECT__
84 1|bar|1|1|0|0|${LOCALHOST}|background
85 1|baz|1|1|0|0|${LOCALHOST}|background
86 1|foo|1|1|0|0|${LOCALHOST}|background
87 __SELECT__
88
89 NAME='select-task-jobs-times.out'
90 sqlite3 "${DB_FILE}" \
91 'SELECT time_submit,time_submit_exit,time_run,time_run_exit FROM task_jobs' \
92 >"${NAME}"
93 # We want words not lines here
94 # shellcheck disable=2013
95 for DATE_TIME_STR in $(sed 's/[|]/ /g' "${NAME}"); do
96 # Parse each string with "date --date=..." without the T
97 run_ok "${NAME}-${DATE_TIME_STR}" \
98 date --date="${DATE_TIME_STR/T/ }"
99 done
100
101 # Shut down with empty task pool (ran to completion)
102 NAME=task-pool.out
103 sqlite3 "${DB_FILE}" 'SELECT name, cycle, status FROM task_pool ORDER BY name' \
104 >"${NAME}"
105 cmp_ok "${NAME}" <'/dev/null'
106
107 NAME='select-task-states.out'
108 sqlite3 "${DB_FILE}" 'SELECT name, cycle, status FROM task_states ORDER BY name' \
109 >"${NAME}"
110 cmp_ok "${NAME}" << __EOF__
111 bar|1|succeeded
112 baz|1|succeeded
113 foo|1|succeeded
114 __EOF__
115
116 NAME='select-inheritance.out'
117 sqlite3 "${DB_FILE}" 'SELECT namespace, inheritance FROM inheritance ORDER BY namespace' \
118 >"${NAME}"
119 cmp_ok "${NAME}" << __EOF__
120 bar|["bar", "root"]
121 baz|["baz", "root"]
122 foo|["foo", "root"]
123 root|["root"]
124 __EOF__
125
126 purge
127 exit