| 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 "cylc cat-log" exits when the log file is deleted |
| 19 |
# or when tail is killed. |
| 20 |
|
| 21 |
. "$(dirname "$0")/test_header" |
| 22 |
set_test_number 2 |
| 23 |
|
| 24 |
# Get PID of tail cmd given the parent cat-log PPID |
| 25 |
get_tail_pid() { |
| 26 |
pgrep -P "$1" tail |
| 27 |
} |
| 28 |
|
| 29 |
init_workflow "${TEST_NAME_BASE}" << __EOF__ |
| 30 |
# whatever |
| 31 |
__EOF__ |
| 32 |
|
| 33 |
log_file="${WORKFLOW_RUN_DIR}/log/foo.log" |
| 34 |
echo "Hello, Mr. Thompson" > "$log_file" |
| 35 |
|
| 36 |
TEST_NAME="${TEST_NAME_BASE}-delete" |
| 37 |
cylc cat-log --mode=tail "$WORKFLOW_NAME" -f foo.log 2>&1 & |
| 38 |
cat_log_pid="$!" |
| 39 |
# Wait for tail to start |
| 40 |
poll get_tail_pid "$cat_log_pid" |
| 41 |
# We should be able to delete the log file |
| 42 |
run_ok "$TEST_NAME" rm "$log_file" |
| 43 |
# cat-log should exit (but exit code does not seem to be consistent across systems) |
| 44 |
poll_pid_done "$cat_log_pid" |
| 45 |
|
| 46 |
echo "Hello, Mr. Thompson" > "$log_file" |
| 47 |
|
| 48 |
TEST_NAME="${TEST_NAME_BASE}-kill" |
| 49 |
cylc cat-log --mode=tail "$WORKFLOW_NAME" -f foo.log 2>&1 & |
| 50 |
cat_log_pid="$!" |
| 51 |
# Wait for tail to start |
| 52 |
poll get_tail_pid "$cat_log_pid" |
| 53 |
kill "$(get_tail_pid "$cat_log_pid")" |
| 54 |
# cat-log should exit non-zero |
| 55 |
poll_pid_done "$cat_log_pid" |
| 56 |
run_fail "${TEST_NAME}_ret" wait "$cat_log_pid" |
| 57 |
|
| 58 |
purge |