Debian Codegraph @

tests/functional/job-file-trap/00-sigusr1.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 handle of SIGUSR1. (Handle a mock job vacation.)
19 # Obviously, job vacation does not happen with background job, and the job
20 # will no longer be poll-able after the kill.
21 . "$(dirname "$0")/test_header"
22
23 skip_all "TODO decide whether to re-instate this"
24
25 run_tests() {
26 set_test_number 5
27 install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}"
28 TEST_NAME="${TEST_NAME_BASE}-validate"
29 run_ok "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}"
30 TEST_NAME="${TEST_NAME_BASE}-run"
31 # Needs to be detaching:
32 workflow_run_ok "${TEST_NAME}" cylc play --reference-test "${WORKFLOW_NAME}"
33
34 # Make sure 1/t1's status file is in place
35 T1_STATUS_FILE="${WORKFLOW_RUN_DIR}/log/job/1/t1/01/job.status"
36
37 poll_grep -E 'CYLC_JOB_ID=' "${T1_STATUS_FILE}"
38 poll_grep -E 'CYLC_JOB_INIT_TIME=' "${T1_STATUS_FILE}"
39
40 # Kill the job and see what happens
41 T1_PID="$(awk -F= '$1=="CYLC_JOB_ID" {print $2}' "${T1_STATUS_FILE}")"
42 kill -s 'USR1' "${T1_PID}"
43 poll_grep -E 'WARNING|vacated/USR1' "${T1_STATUS_FILE}"
44 poll_grep_workflow_log 'vacated/USR1'
45 sleep 1 # a bit of extra time for workflow db update to complete
46 sqlite3 "${WORKFLOW_RUN_DIR}/log/db" \
47 "SELECT status FROM task_states WHERE name=='t1';" \
48 >"${TEST_NAME}-db-t1" 2>'/dev/null'
49 grep_ok "^\(submitted\|running\)$" "${TEST_NAME}-db-t1"
50 # Start the job again and see what happens
51 mkdir -p "${WORKFLOW_RUN_DIR}/work/1/t1/"
52 touch "${WORKFLOW_RUN_DIR}/work/1/t1/file" # Allow t1 to complete
53 "${WORKFLOW_RUN_DIR}/log/job/1/t1/01/job" <'/dev/null' >'/dev/null' 2>&1 &
54 # Wait for workflow to complete
55 poll_workflow_stopped
56 # Test t1 status in DB
57 sqlite3 "${WORKFLOW_RUN_DIR}/log/db" \
58 "SELECT status FROM task_states WHERE name=='t1';" >"${TEST_NAME}-db-t1"
59 cmp_ok "${TEST_NAME}-db-t1" - <<<'succeeded'
60 # Test reference
61 grep_ok 'WORKFLOW REFERENCE TEST PASSED' "${WORKFLOW_RUN_DIR}/log/scheduler/log"
62 purge
63 exit
64 }
65
66 # Programs running in some environment is unable to trap SIGUSR1. E.g.:
67 # An environment documented in this comment:
68 # https://github.com/cylc/cylc-flow/pull/1648#issuecomment-149348410
69 trap 'run_tests' 'SIGUSR1'
70 kill -s 'SIGUSR1' "$$"
71 sleep 1
72 skip_all 'Program not receiving SIGUSR1'